As reported: Tower Research Capital online assessment for 2027 graduates (2026):
Nlabelled machines, machineiholdingA[i]units of workload with a total of exactlyN; build a tree network on all machines; then you may repeatedly move one unit between two machines whose distance in the tree is exactly 2; a network is stable if every machine can end with exactly one unit; count the stable labelled trees modulo1,000,000,007.
There are n labelled machines 1..n; machine i holds A[i] units of workload, and A[1] + … + A[n] = n.
You build a communication network that is a tree on all n machines. Once built, you may repeat this move any number of times: choose two machines u and v whose distance in the tree is exactly 2, and move one unit from u to v (u must hold at least one unit).
A tree is stable if it is possible to end with every machine holding exactly one unit. Count the distinct stable labelled trees (two trees differ if their edge sets differ), modulo 10^9 + 7.
Example 1
A = [1,1,1]
Output: 3
Already balanced: all 3 labelled trees on 3 machines are stable.
Example 2
A = [2,0,1]
Output: 1
Only the path with machine 3 in the middle works: then machines 1 and 2 are at distance 2 and machine 1 can pass a unit to machine 2.
Example 3
A = [3,0,0]
Output: 0
Constraints: 1 ≤ n ≤ 200; 0 ≤ A[i] ≤ n; ΣA[i] = n.
Code runner format: one JSON value per line: A. Implement countStableTrees(A).