Find the maximal value for $ \left| \int_{0}^{1}(f(x))^2-f(x)dx \right| .$ 
Suppose $ f $ is a continuous function from $ [0, 1] $ to $ [-1, 1] $ with $ |f(x)|\leq x, x\in [0, 1] $. Find the maximal value for $$ \left| \int_{0}^{1}(f(x))^2-f(x)dx \right| .$$

I have tried the following:
\begin{align*} \left| \int_{0}^{1}(f(x))^2-f(x)dx \right|&=\left| \int_{0}^{1}(f(x)-\frac{1}{2})^2-\frac{1}{4})dx \right| \\
&=\left| \int_{0}^{1}(f(x)-\frac{1}{2})^2dx-\frac{1}{4}\right|
\end{align*} 
So we have to find some $ f(x) $ to make $ \int_{0}^{1}(f(x)-\frac{1}{2})^2dx $ as far from $ \frac{1}{4} $ as possible. Then I am stuck...
 A: Consider the function $g(x) = x^2 - x$ defined on the interval $[-a, a]$, where $0 \le a \le 1$. Where is the maximum of $g(x)$? What is this maximum value?
Since $g(x)$ is a convex parabola, with only local minima in the interior of the interval the maximum must occur at an endpoint, i.e. at $a$ or $-a$. Comparing, we have,
$$g(-a) = a^2 + a \ge a^2 - a = g(a),$$
so the maximum value occurs at $x = -a$.
Now, if $f : [0, 1] \to [-1, 1]$, with $|f(x)| \le x$ for all $x \in [0, 1]$, then
$$f(x)^2 - f(x) \le x^2 + x,$$
using the above with $a = x$. This maximum is achieved when $f(x) = -x$. Given this pointwise inequality, it follows that
$$\int_0^1 f(x)^2 - f(x) \; \mathrm{d}x \le \int_0^1 x^2 + x \; \mathrm{d}x = \frac{5}{6}.$$
A: Let $A=\{f\in \mathcal C([0,1],[-1,1])\;,\; \forall x, |f(x)|\leq x\}$. It is not hard to prove that 
$$\sup_{f\in A}\left|\int_0^1f^2-f \right|=  \max\left(\sup_{f\in A}\left[\int_0^1f^2-f\right], -\inf_{f\in A}\left[\int_0^1f^2-f\right] \right)$$
Besides, for $f\in A$, $f^2(x)\leq x^2$, thus $\int_0^1 f^2-f\leq \int _0^1(x^2+x) dx=\frac 56$, and this upper bound is attained for $f(x)=-x$, hence $\sup_{f\in A}\left[\int_0^1f^2-f\right] = \max_{f\in A}\left[\int_0^1f^2-f\right]=\frac 56$.
Note also that $\int f^2-f\geq -\int_0^1 f\geq -\int_0^1 x=-\frac 12$. Hence $\inf_{f\in A}\left[\int_0^1f^2-f\right]\geq -\frac 12$ and 
$$\max\left(\sup_{f\in A}\left[\int_0^1f^2-f\right], -\inf_{f\in A}\left[\int_0^1f^2-f\right] \right) = \sup_{f\in A}\left[\int_0^1f^2-f\right] = \max_{f\in A}\left[\int_0^1f^2-f\right]=\frac 56$$
thus $$\sup_{f\in A}\left|\int_0^1f^2-f \right|=\frac 56$$
and the upper bound is attained for $x\mapsto -x$.
