#Lutece0384. Crazy Thairs
Crazy Thairs
Migrated from Lutece 384 Crazy Thairs
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
These days, Sempr is crazed on one problem named Crazy Thair. Given () numbers, and their absolute value are no more than . Crazy Thair is a group of numbers {} satisfying:
For example, in the sequence {},there are four Crazy Thair groups: {}, {}, {} and {}.
Could you help Sempr to count how many Crazy Thairs in the sequence?
Input
Input contains several test cases. Each test case begins with a line containing a number , followed by a line containing numbers.
Output
Output the amount of Crazy Thairs in each sequence.
Samples
5
1 2 3 4 5
7
2 1 3 4 5 7 6
7
1 2 3 4 5 6 7
1
4
21
Note
The data used in this problem is unofficial data prepared by pfctgeorge. So any mistake here does not imply mistake in the offcial judge data.
Resources
POJ Monthly--2007.09.09, tdzl2003