#TP0000052. Truyền thuyết về hai vương quốc (A Tale of Two Lands)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truyền thuyết về hai vương quốc (A Tale of Two Lands)
A Tale of Two Lands
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A legend describes two closed intervals determined by integers and . Interval A has endpoints and , while interval V has endpoints and . Within each interval, the endpoints are understood in increasing order.
A pair is valid when the whole interval A is contained in interval V, including their endpoints.
You are given pairwise distinct integers. Choose two different numbers as . Count the valid unordered pairs; swapping and does not produce a new pair.
Input
- The first line contains an integer : the number of candidate integers.
- The second line contains exactly pairwise distinct integers .
Output
Print one integer: the number of unordered pairs satisfying the interval-containment condition.
Subtasks
- Subtask 1 (20 points): ; for every ; all are pairwise distinct.
- Subtask 2 (30 points): ; for every ; all are pairwise distinct.
- Subtask 3 (50 points): ; for every ; all are pairwise distinct.
Examples
Input
3
2 5 -3
Output
2
Explanation
The unordered pairs are , , and . For , the intervals are and , so containment fails. For they are and , and for they are and ; both latter pairs work. The answer is .