| Number of Battlefields | 
In the previous problem, we assume the perimeter of the figure equals to p, how many battlefields are possible? For example, there are no battlefields possible for p < 8, but two for p = 8:
 
Here are the nine battlefields for p=10:
 
You're asked to output the number of battlefields modulo 987654321.
 p
p 109), the perimeter of the battlefield. 
The input is terminated by p = 0.
109), the perimeter of the battlefield. 
The input is terminated by p = 0.
8 9 10 0
0 2 0 9
Problemsetter: Rujia Liu, Special Thanks: Yiming Li, Tanaeem M Moosa & Sohel Hafiz