#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
  istringstream in(s);
  out.clear();
  copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
static void redirect(int argc, const char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (argc > 1) {
    static filebuf f;
    f.open(argv[1], ios::in);
    cin.rdbuf(&f);
    if (!cin) {
      cerr << "Failed to open '" << argv[1] << "'" << endl;
      exit(1);
    }
  }
  if (argc > 2) {
    static filebuf f;
    f.open(argv[2], ios::out | ios::trunc);
    cout.rdbuf(&f);
    if (!cout) {
      cerr << "Failed to open '" << argv[2] << "'" << endl;
    }
  }
}
struct impossible {};
static constexpr int GOOD = -1;
struct node {
  array<int, 2> dp;
  array<int, 2> idp;
  int size = 1;
  int parent = -1;
  vector<int> edges;
  int good_sub = 0;
  vector<int> special;
};
static vector<node> nodes;
static int combine(int a, int b) {
  if (a == GOOD || b == GOOD)
    return a + b - GOOD;
  else
    return 0;
}
static int sum(int a, int b) {
  if (a < 0)
    return min(a, b);
  else
    return a + b;
}
static array<int, 2> mini(const vector<array<int, 2>> &sdp, int good_sub) {
  array<int, 2> out;
  if (sdp.empty()) {
    out[0] = 1 + good_sub;
    out[1] = GOOD;
  } else {
    out[1] = GOOD;
    for (const auto &v : sdp) out[1] = combine(out[1], v[0]);
    out[0] = 0;
    for (int i = 0; i < ((long long)(sdp).size()); i++) {
      int score = GOOD;
      for (int j = 0; j < ((long long)(sdp).size()); j++)
        score = combine(score, sdp[j][i == j]);
      out[0] = sum(out[0], score);
    }
  }
  return out;
}
static void down(int root, int parent) {
  node &n = nodes[root];
  n.parent = parent;
  n.dp[0] = 1;
  n.dp[1] = GOOD;
  vector<int> &special = n.special;
  int &good_sub = n.good_sub;
  for (int v : n.edges)
    if (v != parent) {
      down(v, root);
      n.size += nodes[v].size;
      if (nodes[v].dp[0] == GOOD)
        good_sub += nodes[v].dp[1];
      else {
        special.push_back(v);
        if (special.size() > 3) throw impossible();
      }
    }
  vector<array<int, 2>> sdp;
  sdp.reserve(special.size());
  for (int v : special) sdp.push_back(nodes[v].dp);
  n.dp = mini(sdp, n.good_sub);
}
static void up(int root) {
  const node &n = nodes[root];
  for (int v : n.edges)
    if (v != n.parent) {
      vector<array<int, 2>> sdp;
      for (int s : n.special)
        if (s != v) sdp.push_back(nodes[s].dp);
      int good_sub = n.good_sub;
      if (nodes[v].dp[0] == GOOD) good_sub -= nodes[v].dp[1];
      if (n.parent != -1) {
        if (n.idp[0] == GOOD)
          good_sub += n.idp[1];
        else
          sdp.push_back(n.idp);
      }
      nodes[v].idp = mini(sdp, good_sub);
      up(v);
    }
}
int main(int argc, const char **argv) {
  redirect(argc, argv);
  int N;
  cin >> N;
  nodes.resize(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    nodes[a].edges.push_back(b);
    nodes[b].edges.push_back(a);
  }
  try {
    if (N & 1) throw impossible();
    down(0, -1);
    up(0);
  } catch (impossible) {
    cout << "0\n";
    return 0;
  }
  long long ans = 0;
  for (int i = 1; i < N; i++) {
    const node &n = nodes[i];
    if (n.size & 1)
      ans += (long long)n.dp[0] * n.idp[0];
    else if (n.dp[0] == GOOD && n.idp[0] == GOOD)
      ans += (long long)n.size * (N - n.size);
  }
  cout << ans << '\n';
  return 0;
}

### Prompt

Create a solution in Cpp for the following problem:

Sloth is bad, mkay? So we decided to prepare a problem to punish lazy guys.

You are given a tree, you should count the number of ways to remove an edge from it and then add an edge to it such that the final graph is a tree and has a perfect matching. Two ways of this operation are considered different if their removed edges or their added edges aren't the same. The removed edge and the added edge can be equal.

A perfect matching is a subset of edges such that each vertex is an endpoint of exactly one of these edges.

Input

The first line contains n (2 ≤ n ≤ 5·105) — the number of vertices.

Each of the next n - 1 lines contains two integers a and b (1 ≤ a, b ≤ n) — the endpoints of one edge. It's guaranteed that the graph is a tree.

Output

Output a single integer — the answer to the problem.

Examples

Input

4
1 2
2 3
3 4


Output

8


Input

5
1 2
2 3
3 4
3 5


Output

0


Input

8
1 2
2 3
3 4
1 5
5 6
6 7
1 8


Output

22

Note

In first sample, there are 8 ways:

  * edge between 2 and 3 turns to edge between 1 and 3, 
  * edge between 2 and 3 turns to edge between 1 and 4, 
  * edge between 2 and 3 turns to edge between 2 and 3, 
  * edge between 2 and 3 turns to edge between 2 and 4, 
  * edge between 1 and 2 turns to edge between 1 and 2, 
  * edge between 1 and 2 turns to edge between 1 and 4, 
  * edge between 3 and 4 turns to edge between 1 and 4, 
  * edge between 3 and 4 turns to edge between 3 and 4. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
  istringstream in(s);
  out.clear();
  copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
static void redirect(int argc, const char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (argc > 1) {
    static filebuf f;
    f.open(argv[1], ios::in);
    cin.rdbuf(&f);
    if (!cin) {
      cerr << "Failed to open '" << argv[1] << "'" << endl;
      exit(1);
    }
  }
  if (argc > 2) {
    static filebuf f;
    f.open(argv[2], ios::out | ios::trunc);
    cout.rdbuf(&f);
    if (!cout) {
      cerr << "Failed to open '" << argv[2] << "'" << endl;
    }
  }
}
struct impossible {};
static constexpr int GOOD = -1;
struct node {
  array<int, 2> dp;
  array<int, 2> idp;
  int size = 1;
  int parent = -1;
  vector<int> edges;
  int good_sub = 0;
  vector<int> special;
};
static vector<node> nodes;
static int combine(int a, int b) {
  if (a == GOOD || b == GOOD)
    return a + b - GOOD;
  else
    return 0;
}
static int sum(int a, int b) {
  if (a < 0)
    return min(a, b);
  else
    return a + b;
}
static array<int, 2> mini(const vector<array<int, 2>> &sdp, int good_sub) {
  array<int, 2> out;
  if (sdp.empty()) {
    out[0] = 1 + good_sub;
    out[1] = GOOD;
  } else {
    out[1] = GOOD;
    for (const auto &v : sdp) out[1] = combine(out[1], v[0]);
    out[0] = 0;
    for (int i = 0; i < ((long long)(sdp).size()); i++) {
      int score = GOOD;
      for (int j = 0; j < ((long long)(sdp).size()); j++)
        score = combine(score, sdp[j][i == j]);
      out[0] = sum(out[0], score);
    }
  }
  return out;
}
static void down(int root, int parent) {
  node &n = nodes[root];
  n.parent = parent;
  n.dp[0] = 1;
  n.dp[1] = GOOD;
  vector<int> &special = n.special;
  int &good_sub = n.good_sub;
  for (int v : n.edges)
    if (v != parent) {
      down(v, root);
      n.size += nodes[v].size;
      if (nodes[v].dp[0] == GOOD)
        good_sub += nodes[v].dp[1];
      else {
        special.push_back(v);
        if (special.size() > 3) throw impossible();
      }
    }
  vector<array<int, 2>> sdp;
  sdp.reserve(special.size());
  for (int v : special) sdp.push_back(nodes[v].dp);
  n.dp = mini(sdp, n.good_sub);
}
static void up(int root) {
  const node &n = nodes[root];
  for (int v : n.edges)
    if (v != n.parent) {
      vector<array<int, 2>> sdp;
      for (int s : n.special)
        if (s != v) sdp.push_back(nodes[s].dp);
      int good_sub = n.good_sub;
      if (nodes[v].dp[0] == GOOD) good_sub -= nodes[v].dp[1];
      if (n.parent != -1) {
        if (n.idp[0] == GOOD)
          good_sub += n.idp[1];
        else
          sdp.push_back(n.idp);
      }
      nodes[v].idp = mini(sdp, good_sub);
      up(v);
    }
}
int main(int argc, const char **argv) {
  redirect(argc, argv);
  int N;
  cin >> N;
  nodes.resize(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    nodes[a].edges.push_back(b);
    nodes[b].edges.push_back(a);
  }
  try {
    if (N & 1) throw impossible();
    down(0, -1);
    up(0);
  } catch (impossible) {
    cout << "0\n";
    return 0;
  }
  long long ans = 0;
  for (int i = 1; i < N; i++) {
    const node &n = nodes[i];
    if (n.size & 1)
      ans += (long long)n.dp[0] * n.idp[0];
    else if (n.dp[0] == GOOD && n.idp[0] == GOOD)
      ans += (long long)n.size * (N - n.size);
  }
  cout << ans << '\n';
  return 0;
}

```