#P4528. [CTSC2008] 图腾
[CTSC2008] 图腾
Description
After completing the study of the Guyuezhou (Gu Yue Zhou) disk cipher, archaeologist Xiao Bu arrived at the west of the South American continent. It is said that long ago two tribes lived on this land: one worshiped lightning, the other worshiped mountains, and they used the shapes of lightning and peaks as their totems.
Xiao Bu’s team discovered a huge mural in a cave. The mural marks points, and measurements show that the horizontal and vertical coordinates of these points are pairwise distinct. Xiao Bu believes the information contained in the mural depends only on the relative positions of these points, so we may set the coordinates as , where is a permutation of .
The team plans to study how many totems are contained in the mural. The definition of a lightning totem is illustrated below (the totem’s type depends only on the relative order of the four -values):

That is, .
The mountain-worship tribe has two clans, so there are two peak totem types, A on the left and B on the right (again, the totem’s type depends only on the relative order of the four -values):

That is, .
That is, .
Xiao Bu’s team wants to know the difference between the counts of the two tribes’ totems. In this problem, you need to compute the number of lightning totems minus the number of peak totems. Since the absolute value of this number can be large, output the result modulo (the remainder must be positive; for example, the remainder of modulo is ).
Input Format
The first line contains an integer , the number of points.
The second line contains integers . It is guaranteed that is a permutation of .
Output Format
Output a single integer, the remainder modulo of the difference between the number of lightning totems and the number of peak totems.
5
1 5 3 2 4
0
4
1 2 4 3
16777215
Hint
[Sample Explanation]
In Sample 1, there is 1 lightning totem (1324) and 1 type B peak totem (1532).
In Sample 2, there is only one type A peak totem (1243), so the difference is , and the answer is .
[Constraints]
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号