Yes there are two formulas.
One is for when there are an even numbers of sticks and
the other is for when there are an odd number of sticks.
If you have sticks of lengths 1,2,3,...,n inches
The formula for when n is even is n(n-2)(2n-5)/24
The formula for when n is odd is (n-1)(n-3)(2n-1)/24
The case above is when there are 9 sticks. Since 9 is odd,
we use the formula, (n-1)(n-3)(2n-1)/24
(n-1)(n-3)(2n-1)/24 = (9-1)*(9-3)*((2*9)-1) /24
=(8*6*17)/24
=34