<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] The stationary points of a quadratic form over a triangle (or hexagon) are simple to locate through Lagrange's multipliers. Your quadratic form is positive definite with eigenvectors $(1,1,1)$, $(-1,0,1)$, $(-1,1,0)$ hence the maximum value is attained on the boundary of the given domain, by convexity. By analyzing the instances $a=0$ and $a=4$ we easily get that the maximum is $28$, attained at $\{a,b,c\}=\{0,2,4\}$.
</s>