Problem:
Score : 1400 points

Problem Statement

There are N turkeys.
We number them from 1 through N.

M men will visit here one by one.
The i-th man to visit will take the following action:

If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.

If either turkey x_i or y_i is alive (but not both): eats the alive one.

If neither turkey x_i nor y_i is alive: does nothing.

Find the number of pairs (i,\ j) (1 ≤ i < j ≤ N) such that the following condition is held:

The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.

Constraints

2 ≤ N ≤ 400

1 ≤ M ≤ 10^5

1 ≤ x_i < y_i ≤ N

Input

Input is given from Standard Input in the following format:

N M
x_1 y_1
x_2 y_2
:
x_M y_M

Output

Print the number of pairs (i,\ j) (1 ≤ i < j ≤ N) such that the condition is held.

Sample Input 1

3 1
1 2

Sample Output 1

2

(i,\ j) = (1,\ 3), (2,\ 3) satisfy the condition.

Sample Input 2

4 3
1 2
3 4
2 3

Sample Output 2

1

(i,\ j) = (1,\ 4) satisfies the condition.
Both turkeys 1 and 4 are alive if:

The first man eats turkey 2.

The second man eats turkey 3.

The third man does nothing.

Sample Input 3

3 2
1 2
1 2

Sample Output 3

0

Sample Input 4

10 10
8 9
2 8
4 6
4 9
7 8
2 8
1 8
3 4
3 4
2 7

Sample Output 4

5

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		boolean[][] pairs = new boolean[n][n];
		for(int i=0; i<n; i++)
			Arrays.fill(pairs[i], true);
		boolean[] dead = new boolean[n];
		Arrays.fill(dead, false);
		LinkedList<Proccessed> list = new LinkedList<Proccessed>();
		int m= sc.nextInt();
		for(int i=0; i<m; i++) {
			int x=sc.nextInt()-1;
			int y=sc.nextInt()-1;
			if(x>y) {
				int tmp = x;
				x=y;
				y=tmp;
			}
			pairs[x][y]=false;
			for(Proccessed p: list) {
				p.remove(pairs, x, y, dead);
			}
			list.add(new Proccessed(x, y, n));
		}
		int count = 0;
		for(int i=0; i<n-1; i++) {
			for(int j= i+1; j<n; j++) {
				if(pairs[i][j]) {
					System.out.println((i+1) + ", " + (j+1));
					count++;
				}
			}
		}
		sc.close();

		System.out.println(count);
	}
}

class Proccessed {
	int x;
	int y;
	boolean[] proccessed;

	public Proccessed(int x, int y, int n) {
		this.x = x;
		this.y = y;
		this.proccessed = new boolean[n];
	}

	public boolean[][] remove(boolean[][] pairs, int newX, int newY, boolean[] dead) {
		int num1;
		int num2;
		if(x==newX && y==newY) {
			// 例外ケース
			dead[x]=true;
			dead[y]=true;
			for(int i=0; i<proccessed.length; i++) {
				if(x<i) pairs[x][i]=false;
				else pairs[i][x]=false;
				if(y<i) pairs[y][i]=false;
				else pairs[i][y]=false;
			}
			return pairs;
		} else if(dead[newX]) {
			dead[newY]=true;
			for(int i=0; i<proccessed.length; i++) {
				if(newY<i) pairs[newY][i]=false;
				else pairs[i][newY]=false;
			}
			return pairs;
		} else if(dead[newY]) {
			dead[newX]=true;
			for(int i=0; i<proccessed.length; i++) {
				if(newX<i) pairs[newX][i]=false;
				else pairs[i][newX]=false;
			}
			return pairs;
		} else if(x==newX) {
			num1=y;
			num2=newY;
		} else if(x==newY) {
			num1=y;
			num2=newX;
		} else if(y==newX) {
			num1=x;
			num2=newY;
		} else if(y==newY) {
			num1=x;
			num2=newX;
		} else {
			return pairs;
		}
		if(num1>num2) {
			int t=num1;
			num1=num2;
			num2=t;
		}
		pairs[num1][num2]=false;

		return pairs;
	}
}