Suppose I am working in a system consisting of $n$ particles. Thus the phase space will be $\mathbb{R}^{6n}$, and both the momentum and position space will be $\mathbb{R}^{3n}$ each.
Then, for some potential function $V$, the Hamiltonian is given by $$H(q, p) = \sum_{i=1}^n \frac{p_i^2}{2m_i} + V(q),\tag{1.2.1}$$ cf. e.g. Glimm & Jaffe p.4.
My question is why exactly are we summing $n$ terms? I thought each $p \in P = \mathbb{R}^{3n}$, so it seems we are off by a factor of 3.
The only thing I can think of is that each momentum component is summed separately, but nothing in the notation suggests this and I always believed the Hamiltonian to be a scalar.
EDIT: After reading a few answers, it seems that $p_i^2$ is to be interpreted as a scalar (i.e. the magnitude of the momentum vector).
As a follow up, suppose I have an observable $f = f(q(t), p(t))$. Some notes I am following claims that $$\frac{\partial f}{\partial t} = \sum_1^n \Big(\frac{p_i}{m_i} \cdot \nabla_{q_i} + F_i(q) \cdot \nabla_{p_i}\Big)f.$$
Clearly this was obtained via the chain rule. However, if each generalized coordinate or momenta is to be indeed viewed as a scalar, how come there is a gradient vector in this expression? When do we view these generalized momenta/coordinates as vectors and when do we view them as scalars? I assume each gradient vector here is in $\mathbb{R}^3$?