Rating changes for last rounds are temporarily rolled back. They will be returned soon.
×

The package for this problem was not updated by the problem writer or Codeforces administration after we've upgraded the judging servers. To adjust the time limit constraint, a solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then the value 800 ms will be displayed and used to determine the verdict.

Codeforces Round 174 (Div. 1) |
---|

Finished |

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

combinatorics

data structures

math

*2800

No tag edit access

The problem statement has recently been changed. View the changes.

×
E. Cow Tennis Tournament

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputFarmer John is hosting a tennis tournament with his *n* cows. Each cow has a skill level *s*_{i}, and no two cows having the same skill level. Every cow plays every other cow exactly once in the tournament, and each cow beats every cow with skill level lower than its own.

However, Farmer John thinks the tournament will be demoralizing for the weakest cows who lose most or all of their matches, so he wants to flip some of the results. In particular, at *k* different instances, he will take two integers *a*_{i}, *b*_{i} (*a*_{i} < *b*_{i}) and flip all the results between cows with skill level between *a*_{i} and *b*_{i} inclusive. That is, for any pair *x*, *y* he will change the result of the match on the final scoreboard (so if *x* won the match, the scoreboard will now display that *y* won the match, and vice versa). It is possible that Farmer John will change the result of a match multiple times. It is not guaranteed that *a*_{i} and *b*_{i} are equal to some cow's skill level.

Farmer John wants to determine how balanced he made the tournament results look. In particular, he wants to count the number of triples of cows (*p*, *q*, *r*) for which the final leaderboard shows that cow *p* beats cow *q*, cow *q* beats cow *r*, and cow *r* beats cow *p*. Help him determine this number.

Note that two triples are considered different if they do not contain the same set of cows (i.e. if there is a cow in one triple that is not in the other).

Input

On the first line are two space-separated integers, *n* and *k* (3 ≤ *n* ≤ 10^{5}; 0 ≤ *k* ≤ 10^{5}). On the next line are *n* space-separated distinct integers, *s*_{1}, *s*_{2}, ..., *s*_{n} (1 ≤ *s*_{i} ≤ 10^{9}), denoting the skill levels of the cows. On the next *k* lines are two space separated integers, *a*_{i} and *b*_{i} (1 ≤ *a*_{i} < *b*_{i} ≤ 10^{9}) representing the changes Farmer John made to the scoreboard in the order he makes it.

Output

A single integer, containing the number of triples of cows (*p*, *q*, *r*) for which the final leaderboard shows that cow *p* beats cow *q*, cow *q* beats cow *r*, and cow *r* beats cow *p*.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3 2

1 2 3

1 2

2 3

Output

1

Input

5 3

5 9 4 1 7

1 7

2 8

3 9

Output

3

Note

In the first sample, cow 3 > cow 1, cow 3 > cow 2, and cow 2 > cow 1. However, the results between cows 1 and 2 and cows 2 and 3 are flipped, so now FJ's results show that cow 1 > cow 2, cow 2 > cow 3, and cow 3 > cow 1, so cows 1, 2, and 3 form a balanced triple.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/24/2024 13:22:51 (l1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|