Let
r=x1x3x5+x2x4x6 and let
s be the cyclic sum in question. Expanding
(x1+x4)(x2+x5)(x3+x6) produces eight triple products, which are exactly the six terms of
s together with the two terms of
r. So
r+s= (x1+x4)(x2+x5)(x3+x6), and by AM-GM this is at most
(31)3=271.
Therefore
s≤271−r≤271−5401=54020−1=54019. Equality needs
x1+x4=x2+x5=x3+x6= 31 with
r=5401: take
x1=x3=103, x5=601, x2=6019, x4=x6=301. Then
r=60009+5400019=54000100=5401, as required.
So the maximum is
54019, and
p+q=19+540=559.