<s>[INST] Maximize $P=a^2+b^2+c^2+ab+ac+bc$ 
For real numbers $a, b, c$ that  satisfy $a + b + c = 6$ and $0\leq a,b,c \leq 4$, 
  maximize $P=a^2+b^2+c^2+ab+ac+bc$. 

My try:

$$\begin{align} \begin{cases} a+b+c=6(1) \\ 0\leq a,b,c\leq4(2) \end{cases} \end{align}$$ $$(1)\Rightarrow \begin{align} \begin{cases} b+c=(6-a) \\b^2+c^2+bc=(6-a)^2-bc \end{cases} \end{align}$$ $$P=a^2+(b^2+c^2+bc)+a(b+c)=a^2+[(6-a)^2-bc]+a(6-a)$$ $$P=(a^2-12a+36)-bc=(a-6)^2-bc (2)\Rightarrow bc\leq 0 \Rightarrow P\geq (a-6)^2$$ When $bc=0 \Rightarrow [{\begin{matrix}b=0\\c=0\end{matrix}}(3)$. From  $(1)$ and $(3)$,  $\Rightarrow 2\leq a\leq 4(4)$ $P_{max} \implies |a-6|$ max satisfy $(4)$ $\implies a=2$ from $(1)$ and $(3)$ $\implies b=c=4$ $\implies P_{max}(a,b,c)=P(4;2;0)=28$

 [/INST] From the fact that $a+b+c=6$, we know that $$36=\left( \sum_{cyc} a \right)^2=\sum_{cyc}a^2+2 \sum_{cyc}ab=P+\sum_{cyc}ab$$
So maximizing $P$ becomes equivalent to minimizing $ab+bc+ca$. 
WLOG, assume that $a$ is the maximum among $a,b,c$. So $a+b+c =6 \le 3a$, hence $4 \ge a \ge 2$ from the condition. 
However, note that $$ab+bc+ca \ge ab+ca= a(b+c)=a(6-a) \ge 8$$
From $4 \ge a \ge 2$. 
Hence the minimum of $ab+bc+ca=8$, when $a=4,b=2, c=0$. Thus, the maximum of $P$ is $36-8=28$. 
We are done!
</s>