Problem:
Score : 500 points

Problem Statement

Rng has a connected undirected graph with N vertices.
Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i.

Rng will add new edges to the graph by repeating the following operation:

Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v.

Find the maximum possible number of edges that can be added.

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq A_i,B_i \leq N

The graph has no self-loops or multiple edges.

The graph is connected.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Find the maximum possible number of edges that can be added.

Sample Input 1

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

Sample Output 1

4

If we add edges as shown below, four edges can be added, and no more.

Sample Input 2

5 5
1 2
2 3
3 1
5 4
5 1

Sample Output 2

5

Five edges can be added, for example, as follows:

Add an edge connecting Vertex 5 and Vertex 3.

Add an edge connecting Vertex 5 and Vertex 2.

Add an edge connecting Vertex 4 and Vertex 1.

Add an edge connecting Vertex 4 and Vertex 2.

Add an edge connecting Vertex 4 and Vertex 3.

Solution in Go (1.6) (judge verdict: Accepted)

package main

import (
	"fmt"
)

func main() {
	nm := scanInts(2)
	n, m := nm[0], nm[1]
	edges := make(map[int64][]int64)
	for _ = range iter(0, m) {
		ab := scanInts(2)
		edges[ab[0]] = append(edges[ab[0]], ab[1])
		edges[ab[1]] = append(edges[ab[1]], ab[0])
	}
	fmt.Println(solve(n, m, edges))
}

type color bool

const (
	blue  = true
	green = false
)

type elm struct {
	node  int64
	color color
}

func solve(n, m int64, edges map[int64][]int64) int64 {
	visited := make(map[int64]bool)
	ans := int64(0)
	for i := range iter(1, n+1) {
		if visited[i] {
			continue
		}
		blueGreen := make(map[color]map[int64]bool)
		blueGreen[blue] = make(map[int64]bool)
		blueGreen[green] = make(map[int64]bool)
		complete := false
		lv := make(map[int64]bool)
		edc := int64(0)
		stack := []elm{elm{node: i, color: blue}}
		blueGreen[blue][i] = true
		for len(stack) > 0 {
			l := len(stack)
			x := stack[l-1]
			stack = stack[:l-1]
			if lv[x.node] {
				continue
			}
			lv[x.node] = true
			visited[x.node] = true
			for _, nxt := range edges[x.node] {
				if blueGreen[x.color][nxt] {
					complete = true
				}
				nxtClr := !x.color
				blueGreen[nxtClr][nxt] = true
				stack = append(stack, elm{node: nxt, color: nxtClr})
			}
			edc += int64(len(edges[x.node]))
		}
		z := int64(len(lv))
		if complete {
			ans += z*(z-1)/2 - edc/2
		} else {
			ans += int64(len(blueGreen[blue])*len(blueGreen[green])) - edc/2
		}
	}
	return ans
}

func scanInts(length int64) []int64 {
	ints := make([]int64, length)
	for i := range iter(0, length) {
		var x int64
		_, _ = fmt.Scan(&x)
		ints[i] = x
	}
	return ints
}

func iter(l int64, r int64) chan int64 {
	var i int64 = l
	c := make(chan int64)
	go func() {
		for i < r {
			c <- i
			i += 1
		}
		close(c)
	}()
	return c
}