5427: 难以忍受的存在争议

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:15 通过:12

题目描述

托马什在贝尔兰的街道上行走时,一直在走失。这并不奇怪!在他的家乡,对于任何一对十字路口,从一个十字路口到另一个十字路口都只有一条路。柏林的首都很不一样!

托马什注意到,即使是简单的歧义也会让他感到困惑。因此,当他看到一组四个不同的交叉点abcd时,从ac有两条路径,一条通过b,另一条通过d,他称该组为该死的菱形。注意,对(ab),(bc),(ad),(dc)应通过道路直接连接。示意性地,下图中显示了一个该死的菱形:

任何十字路口之间的其他道路都不会使菱形对托马什更有吸引力,因此四个十字路口对他来说仍然是一个“该死的菱形”。

考虑到柏林的首都有n个十字路口和m条道路,所有道路都是单向的,并且是事先知道的,请找出城市中该死的菱形的数量。

当比较菱形时,交点bd的顺序无关紧要。

Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital of Berland is very different!
Tomash has noticed that even simple cases of ambiguity confuse him. So, when he sees a group of four distinct intersections a, b, c and d, such that there are two paths from a to c − one through b and the other one through d, he calls the group a "damn rhombus". Note that pairs (a,b), (b,c), (a,d), (d,c) should be directly connected by the roads. Schematically, a damn rhombus is shown on the figure below:
Other roads between any of the intersections don't make the rhombus any more appealing to Tomash, so the four intersections remain a "damn rhombus" for him.
Given that the capital of Berland has n intersections and m roads and all roads are unidirectional and are known in advance, find the number of "damn rhombi" in the city.
When rhombi are compared, the order of intersections b and d doesn't matter.
Input
The first line of the input contains a pair of integers n, m (1≤n≤3000,0≤m≤30000) − the number of intersections and roads, respectively. Next m lines list the roads, one per line. Each of the roads is given by a pair of integers ai,bi (1≤ai,bin;aibi) − the number of the intersection it goes out from and the number of the intersection it leads to. Between a pair of intersections there is at most one road in each of the two directions.
It is not guaranteed that you can get from any intersection to any other one.
Output
Print the required number of "damn rhombi".
Examples
Input
5 4
1 2
2 3
1 4
4 3
Output
1
Input
4 12
1 2
1 3
1 4
2 1
2 3
2 4
3 1
3 2
3 4
4 1
4 2
4 3
Output
12

输入格式

输入的第一行包含一对整数nm1≤n≤3000,0≤m≤30000),分别表示交叉口和道路的数量。接下来的m行列出了道路,每行一条。每一条道路都由一对整数aibi1≤aibi≤nai≠bi)表示,即它所经过的交叉口的数量和它所通向的交叉口数量。在一对交叉口之间,两个方向中的每个方向最多有一条道路。

不能保证你能从任何十字路口到任何其他十字路口。

输出格式

打印所需数量的“该死的菱形”。



Input
5 4
1 2
2 3
1 4
4 3
Output
1
Input
4 12
1 2
1 3
1 4
2 1
2 3
2 4
3 1
3 2
3 4
4 1
4 2
4 3
Output
12

输入样例 复制

5 4
1 2
2 3
1 4
4 3

输出样例 复制

1