The Bugs
Time limit2sMemory limit512 MB
Given N integers, print the distinct labels of all subsequence triplets, where each label is the smallest positive triplet with the same sign pattern.
- Level
Medium5 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Statement
A submarine painted in bright plastic lemon color is investigating ocean depths and measuring the concentration of plastic yoctoparticles in the water. Each measurement (due to an ingenious choice of units) is a positive integer. The measurement system is recent, poorly tested, and prone to errors. The project management suspects it is full of bugs. Mother Mary also suspects it is full of bugs. Everybody cries: Help!
To identify and correct the bugs, they decided to take the sequence of measured concentrations and analyze all triplets that occur in the sequence.
A triplet is a sequence of three integers. Each triplet has a characteristic. The characteristic of a triplet is the triplet , where is -1, 0, or 1 when is negative, zero, or positive.
A triplet is smaller than if and only if the first nonzero value in is negative. The label of a triplet is the smallest triplet whose values are all positive and whose characteristic equals the characteristic of .
A measured triplet is a triplet that is a subsequence of the measurement sequence. Its elements appear in the sequence in the same order as in the triplet, but they do not need to be adjacent.
Before analysis, the measured triplets are grouped by their labels. The management wants to know the set of labels of all measured triplets in advance.
Input
The first line contains one integer (), the number of measurements. The next line contains integers (), each representing one measurement.
Output
Print all distinct labels of the measured triplets that can be obtained from the given sequence, in increasing order, one per line. Print each label with no spaces between its consecutive elements.