{"raw_statement":[{"iden":"problem statement","content":"We have a grid with $N$ rows and $N$ columns. The cell at the $i$\\-th row and $j$\\-th column is denoted ($i$, $j$).\nInitially, $M$ of the cells are painted black, and all other cells are white. Specifically, the cells ($a_1$, $b_1$), ($a_2$, $b_2$), $...$, ($a_M$, $b_M$) are painted black.\nSnuke will try to paint as many white cells black as possible, according to the following rule:\n\n*   If two cells ($x$, $y$) and ($y$, $z$) are both black and a cell ($z$, $x$) is white for integers $1≤x,y,z≤N$, paint the cell ($z$, $x$) black.\n\nFind the number of black cells when no more white cells can be painted black."},{"iden":"constraints","content":"*   $1≤N≤10^5$\n*   $1≤M≤10^5$\n*   $1≤a_i,b_i≤N$\n*   All pairs ($a_i$, $b_i$) are distinct."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $M$\n$a_1$ $b_1$\n$a_2$ $b_2$\n$:$\n$a_M$ $b_M$"},{"iden":"sample input 1","content":"3 2\n1 2\n2 3"},{"iden":"sample output 1","content":"3\n\nIt is possible to paint one white cell black, as follows:\n\n*   Since cells ($1$, $2$) and ($2$, $3$) are both black and a cell ($3$, $1$) is white, paint the cell ($3$, $1$) black."},{"iden":"sample input 2","content":"2 2\n1 1\n1 2"},{"iden":"sample output 2","content":"4\n\nIt is possible to paint two white cells black, as follows:\n\n*   Since cells ($1$, $1$) and ($1$, $2$) are both black and a cell ($2$, $1$) is white, paint the cell ($2$, $1$) black.\n*   Since cells ($2$, $1$) and ($1$, $2$) are both black and a cell ($2$, $2$) is white, paint the cell ($2$, $2$) black."},{"iden":"sample input 3","content":"4 3\n1 2\n1 3\n4 4"},{"iden":"sample output 3","content":"3\n\nNo white cells can be painted black."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}