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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;

const int mx = 100000 + 5;
int n, m, b[2] = {0};
char mark[mx];
// struct edge{
//     int l, r;
//     bool operator<(edge e){
//         if(l != e.l){
//             return l < e.l;
//         }
//         else{
//             return r < e.r;
//         }
//     }
// }ed[mx];

vector<int>pt[mx];

bool judgeBipartite(int now, char c){
    if(mark[now] < 0){
        mark[now] = c;
        ++b[c];
        bool ans = true;
        for(int i = 0; i < pt[now].size() && ans; ++i){
            ans = ans && judgeBipartite(pt[now][i], !c);
        }
        return ans;
    }
    else if(mark[now] == c){
        return true;
    }
    return false;
}
// bool judgeBipartite(point * pt, int start){
//     queue<int>qpt;
//     qpt.push(start);
//     while(!qpt.empty()){
//         int now = qpt.front();
//         qpt.pop();
//         for(int i = 0; i < pt[now].next.size(); ++i){
//             char & l = mark[pt[now].next[i]];
//             if(l < 0){
//                 l = 1 ^ mark[now];
//                 ++b[l];
//                 qpt.push(pt[now].next[i]);
//             }
//             else if(!(l ^ mark[now])){
//                 return false;
//             }
//         }
//     }
//     return true;
// }

int main(){
    memset(mark, -1, sizeof(mark));
    scanf("%d%d", &n, &m);
    for(int i = 0, x, y; i < m; ++i){
        scanf("%d%d", &x, &y);
        pt[x].push_back(y);
        pt[y].push_back(x);
    }
    bool judge = true;
    for(int i = 1; i <= n && judge; ++i){
        if(mark[i] < 0){
            judge = judge && judgeBipartite(i, 0);
        }
    }
    // for(int i = 0, x, y; i < m; ++i){
    //     scanf("%d%d", &x, &y);
    //     ed[i].l = min(x, y);
    //     ed[i].r = max(x, y);
    // }
    // sort(ed, ed + m);
    // mark[1] = 0;
    // int b[2] = {1};
    // for(int i = 0; i < m; ++i){
    //     char & l = mark[ed[i].l], &r = mark[ed[i].r];
    //     // cout<<ed[i].l<<(int)l<<' '<<' '<<ed[i].r<<' '<<(int)r<<endl;
    //     if(l < 0 || r < 0){
    //         if(l < 0){
    //             l = 1 ^ r;
    //             ++b[l];
    //         }
    //         else{
    //             r = 1 ^ l;
    //             ++b[r];
    //         }
    //     }
    //     else if(!(l ^ r)){
    //         judge = false;
    //         break;
    //     }
    // }
    // for(int i = 0; i < n; ++i){
    //     cout<<i<<' '<<(int)mark[i]<<endl;
    // }
    if(judge){
        // cout << b[0] << " " << b[1] << endl;
        printf("%lld\n", (long long)b[0] * b[1] - m);
    }
    else{
        // cout << n <<' '<<m<<endl;
        printf("%lld\n", (long long)n * (n - 1) / 2 - m);
    }
    return 0;
}