Solution (source code)

= Solution

For <nonequivalent p-s and p-p term counting>, the closed $3s^2$ shell has $L=S=0$. For $3p4s$, the open orbitals give $L=1$ and $S=0,1$, hence
$$
\boxed{3p4s:\quad{}^1P_1,\quad{}^3P_{0,1,2}.}
$$
<Hund's rules> predict the order $^3P_0<{}^3P_1<{}^3P_2<{}^1P_1$.

For $3p4p$, the electrons are in \b[nonequivalent orbitals]. All $L=0,1,2$ and $S=0,1$ combinations are allowed:
$$
\boxed{3p4p:\quad{}^1S_0,\ {}^1P_1,\ {}^1D_2,\
{}^3S_1,\ {}^3P_{0,1,2},\ {}^3D_{1,2,3}.}
$$
Applying maximum <spin> first, maximum <orbital angular momentum> next, and smallest $J$ first for these less-than-half-filled open subshells gives the qualitative ordering
$$
\boxed{{}^3D_1<{}^3D_2<{}^3D_3<{}^3P_0<{}^3P_1<{}^3P_2
<{}^3S_1<{}^1D_2<{}^1P_1<{}^1S_0.}
$$
The state counts are $12$ for $3p4s$ and $36$ for $3p4p$. Imposing the equivalent-$p^2$ restrictions would incorrectly discard allowed terms. These are Hund-rule predictions; exact interleavings in a real excited configuration require the actual Coulomb and spin-orbit matrix elements.