QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#10302. 天天爱下棋

Statistics

Student Z finds playing chess very interesting, so he decided to create a game called "Everyday Love Chess". "Everyday Love Chess" is a card game where players need to combine cards from their inventory into a deck to compete against other players.

Each card in this game has two values: attack power and defense value. Card A can defeat card B if and only if the attack power of card A is greater than or equal to the defense value of card B.

A deck in this game consists of exactly three distinct cards, placed in order into three card slots. For the sake of fairness, three cards can form a deck if and only if:

  • The card in slot 1 can defeat the card in slot 2.
  • The card in slot 2 can defeat the card in slot 3.
  • The card in slot 3 can defeat the card in slot 1.

After development, Student Z invited Student H to help test the game and gave him $n$ initial cards.

Now, Student H wants to know how many essentially different decks he can form. Two decks are different if and only if there is at least one card slot that contains a different card.

Input

Read data from standard input.

The first line of input contains two integers $s$ and $n$, representing the subtask number and the number of cards, respectively. For the sample, $s$ indicates that the sample shares the same constraints as test case $s$.

The next $n$ lines each contain two integers $a_i, d_i$, representing the attack power and defense value of the $i$-th card, respectively.

Output

Output to standard output.

Output a single integer representing the total number of essentially different decks Student H can form.

Examples

Input

1 10
7 4
18 18
10 15
12 3
12 15
9 7
10 1
3 19
11 7
8 13

Output

60

Example 2

See ex_2.in and ex_2.ans in the download directory.

This sample satisfies the conditions of subtask 4.

Example 3

See ex_3.in and ex_3.ans in the download directory.

This sample satisfies the conditions of subtask 6.

Subtasks

For all test data, it is guaranteed that $1 \le n \le 2 \times 10^{5}$ and $1 \le a_i, d_i \le 2 \times n$.

SubtaskScore$n\le$Special Property
15500None
22,000
3105,000
4$2 \times 10^{4}$
525$5 \times 10^{4}$
630$2 \times 10^{5}$
715Yes

Special Property: It is guaranteed that $\forall 1\le i \le n, 1\le a_i, d_i \le 500$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.