Ecosystem |
There are various food chains in any ecosystem, hawk, mouse and corn to name one. Mice feed on corn, hawks eat mice and life goes on. Given the relations between the species one can easily create food chains.
One can also determine whether a chain is a cyclic one with caterpillars, plants, fungi and bacteria, as an example of cyclic chain. Caterpillars feed on plants, plants use organic substances produced by bacteria and fungi by decomposition of dead bodies of organisms such as caterpillars. These constitute a 3-member cyclic food chain.
Your task is to find 3-member cyclic food chains.
You should not print all identical chain (only that one with species sorted with ascend or descend order). Chains should be sorted. This means that the chains 1 2 4, 1 2 3 and 3 2 1 should be printed in the following order:
1 2 3 1 2 4 3 2 1
Assumptions: number of species in one test belongs to a range [3, 100]
3 0 1 0 0 0 1 1 0 0 3 0 0 1 1 0 0 0 1 0 3 0 1 1 1 0 1 1 1 0 4 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0
1 2 3 total:1 3 2 1 total:1 1 2 3 3 2 1 total:2 1 2 3 1 2 4 1 3 4 2 3 4 3 2 1 4 2 1 4 3 1 4 3 2 total:8