#P1302B. DAG

    ID: 3606 Type: RemoteJudge 3000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>constructive algorithms

DAG

Description

This is an unusual problem in an unusual contest, here is the announcement: http://codeforces.com/blog/entry/73543

You are given a directed acyclic graph GG with nn vertices and mm edges. Denote by R(v)R(v) the set of all vertices uu reachable from vv by moving along the edges of GG. Find v=1nR(v)2\sum\limits_{v=1}^n |R(v)|^2.

The first line contains two integers n,mn, m (1n,m51041 \leq n, m \leq 5 \cdot 10^4) denoting the number of vertices and the number of edges of GG.

Each of the next mm lines contains two integers u,vu, v (1uvn1 \leq u \neq v \leq n), denoting the edge from uu to vv.

It's guaranteed that the given graph does not contain any cycles.

Print one integer — the answer to the problem.

Input

The first line contains two integers n,mn, m (1n,m51041 \leq n, m \leq 5 \cdot 10^4) denoting the number of vertices and the number of edges of GG.

Each of the next mm lines contains two integers u,vu, v (1uvn1 \leq u \neq v \leq n), denoting the edge from uu to vv.

It's guaranteed that the given graph does not contain any cycles.

Output

Print one integer — the answer to the problem.

Sample Input 1

5 4
1 2
2 3
3 4
4 5

Sample Output 1

55

Sample Input 2

12 6
1 2
3 4
5 6
8 7
10 9
12 11

Sample Output 2

30

Sample Input 3

7 6
1 2
1 3
2 4
2 5
3 6
3 7

Sample Output 3

45