4. Find all functions $f: \mathbb{Z} \rightarrow \mathbb{Z}$ that satisfy $f(n)+f(n+1)=2n+1$ for any integer $n$ and additionally

$$
\sum_{i=1}^{63} f(i)=2015
$$
Solution. Note that $f(n+1)=2n+1-f(n)$, which allows us to find successively

$$
f(1)=1-f(0), \quad f(2)=3-f(1)=2+f(0), \quad f(3)=5-f(2)=3-f(0), \ldots
$$

This allows us to conjecture that $f(n)=n+(-1)^{n} f(0)$ for all $n \geq 0$, which we can prove by induction, being true as already seen for $n=1,2,3$, and if it is true for $n$, then

$$
f(n+1)=2n+1-n-(-1)^{n} f(0)=n+1+(-1)^{n+1} f(0)
$$

So it is true for all positive integers $n$. Backward induction, using that $f(n)=$ $2n+1-f(n+1)$ allows us to verify equally that this expression is indeed valid for all integers $n$, including negative ones.

Note now that in $\{1,2,3, \ldots, 63\}$ there is exactly one more odd integer than even integers. In the image of each even integer, $f(0)$ appears with a positive sign, and in the image of each odd integer with a negative sign, so

$$
2015=\sum_{i=1}^{63} f(i)=-f(0)+\sum_{i=1}^{63} i=\frac{63 \cdot 64}{2}-f(0)=2016-f(0)
$$

We conclude that $f(0)=1$, so the only function that satisfies the conditions of the statement is

$$
f(n)=n+(-1)^{n}
$$