Under construction

Still being built. Things may change

Monochromatic Triangles

Interview

Time limit1sMemory limit128 MB

Summary
Given n points and a list of red edges (all other pairs are black), count the triangles whose three sides share one color.
Level

Medium5 of 10

Topics
Combinatorics, Graph, Brute force, Implementation
Solved
No attempts yet

Problem

There are nn points in the plane, and no three of them are collinear. Every pair of points is joined by a segment colored either red or black. A triangle whose three sides all have the same color is called a monochromatic triangle. Given the list of all red segments, count the monochromatic triangles. Every pair of points not in the list is joined by a black segment.

Write a program that:

  • reads the number of points, the number of red segments, and their list from standard input,
  • computes the number of monochromatic triangles,
  • writes the result to standard output.

Input

The first line contains the number of points nn (3≤n≤1,0003 \le n \le 1{,}000). The second line contains the number of red segments mm (0≤m≤250,0000 \le m \le 250{,}000). Each of the next mm lines contains two integers pp and kk, separated by a single space, the endpoints of a red segment (1≤p<k≤n1 \le p < k \le n). Every other pair of points is black.

Output

Print a single integer: the number of monochromatic triangles.

Examples4

  1. Example 1

    Input
    6
    9
    1 2
    2 3
    2 5
    1 4
    1 6
    3 4
    4 5
    5 6
    3 6
    
    Expected output
    2
    
  2. Example 2

    Input
    3
    0
    
    Expected output
    1
    
  3. Example 3

    Input
    3
    3
    1 2
    1 3
    2 3
    
    Expected output
    1
    
  4. Example 4

    Input
    3
    1
    1 2
    
    Expected output
    0