#include <bits/stdc++.h>
using namespace std;
int n, m, l[500005], r[500005], cnt, head[500005], nxt[2 * 500005],
    num[2 * 500005], sz[500005];
long long ans;
struct node {
  int v[2][2];
  int* operator[](int x) { return v[x]; }
} f[500005], emp, A[2 * 500005], B[2 * 500005];
node operator+(node p, node q) {
  int i, j, k, l;
  node o = emp;
  for (i = 0; i < 2; i++)
    for (j = 0; j < 2; j++)
      for (k = 0; i + k < 2; k++)
        for (l = 0; j + l < 2; l++) o[i + k][j + l] += p[i][j] * q[k][l];
  return o;
}
void dp1(int t, int fa) {
  int i;
  node v;
  v = emp, v[0][0] = 1, sz[t] = 1;
  for (i = head[t]; i; i = nxt[i])
    if (num[i] != fa) {
      dp1(num[i], t);
      v = v + f[num[i]];
      sz[t] += sz[num[i]];
    }
  f[t][0][0] = v[1][0];
  f[t][0][1] = v[1][1] + v[0][0];
  f[t][1][0] = v[0][0];
  f[t][1][1] = v[0][1];
}
void dp2(int t, int fa) {
  int i, p;
  node v;
  l[t] = cnt + 1;
  for (i = head[t]; i; i = nxt[i]) ++cnt, A[cnt] = B[cnt] = f[num[i]];
  r[t] = cnt;
  for (i = l[t] + 1; i <= r[t]; i++) A[i] = A[i - 1] + A[i];
  for (i = r[t] - 1; i >= l[t]; i--) B[i] = B[i + 1] + B[i];
  for (i = head[t], p = l[t]; i; i = nxt[i], p++) {
    if (num[i] == fa) continue;
    v = emp, v[0][0] = 1;
    if (p > l[t]) v = A[p - 1] + v;
    if (p < r[t]) v = v + B[p + 1];
    f[t][0][0] = v[1][0];
    f[t][0][1] = v[1][1] + v[0][0];
    f[t][1][0] = v[0][0];
    f[t][1][1] = v[0][1];
    ans += 1LL * f[t][0][0] * f[num[i]][0][0] * (n - sz[num[i]]) * sz[num[i]] +
           1LL * f[t][0][1] * f[num[i]][0][1];
    dp2(num[i], t);
  }
  f[t][0][0] = A[r[t]][1][0];
  f[t][0][1] = A[r[t]][1][1] + A[r[t]][0][0];
  f[t][1][0] = A[r[t]][0][0];
  f[t][1][1] = A[r[t]][0][1];
}
int main() {
  int i, x, y;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    num[++m] = y, nxt[m] = head[x], head[x] = m;
    num[++m] = x, nxt[m] = head[y], head[y] = m;
  }
  dp1(1, 0);
  dp2(1, 0);
  cout << ans;
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

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;
int n, m, l[500005], r[500005], cnt, head[500005], nxt[2 * 500005],
    num[2 * 500005], sz[500005];
long long ans;
struct node {
  int v[2][2];
  int* operator[](int x) { return v[x]; }
} f[500005], emp, A[2 * 500005], B[2 * 500005];
node operator+(node p, node q) {
  int i, j, k, l;
  node o = emp;
  for (i = 0; i < 2; i++)
    for (j = 0; j < 2; j++)
      for (k = 0; i + k < 2; k++)
        for (l = 0; j + l < 2; l++) o[i + k][j + l] += p[i][j] * q[k][l];
  return o;
}
void dp1(int t, int fa) {
  int i;
  node v;
  v = emp, v[0][0] = 1, sz[t] = 1;
  for (i = head[t]; i; i = nxt[i])
    if (num[i] != fa) {
      dp1(num[i], t);
      v = v + f[num[i]];
      sz[t] += sz[num[i]];
    }
  f[t][0][0] = v[1][0];
  f[t][0][1] = v[1][1] + v[0][0];
  f[t][1][0] = v[0][0];
  f[t][1][1] = v[0][1];
}
void dp2(int t, int fa) {
  int i, p;
  node v;
  l[t] = cnt + 1;
  for (i = head[t]; i; i = nxt[i]) ++cnt, A[cnt] = B[cnt] = f[num[i]];
  r[t] = cnt;
  for (i = l[t] + 1; i <= r[t]; i++) A[i] = A[i - 1] + A[i];
  for (i = r[t] - 1; i >= l[t]; i--) B[i] = B[i + 1] + B[i];
  for (i = head[t], p = l[t]; i; i = nxt[i], p++) {
    if (num[i] == fa) continue;
    v = emp, v[0][0] = 1;
    if (p > l[t]) v = A[p - 1] + v;
    if (p < r[t]) v = v + B[p + 1];
    f[t][0][0] = v[1][0];
    f[t][0][1] = v[1][1] + v[0][0];
    f[t][1][0] = v[0][0];
    f[t][1][1] = v[0][1];
    ans += 1LL * f[t][0][0] * f[num[i]][0][0] * (n - sz[num[i]]) * sz[num[i]] +
           1LL * f[t][0][1] * f[num[i]][0][1];
    dp2(num[i], t);
  }
  f[t][0][0] = A[r[t]][1][0];
  f[t][0][1] = A[r[t]][1][1] + A[r[t]][0][0];
  f[t][1][0] = A[r[t]][0][0];
  f[t][1][1] = A[r[t]][0][1];
}
int main() {
  int i, x, y;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    num[++m] = y, nxt[m] = head[x], head[x] = m;
    num[++m] = x, nxt[m] = head[y], head[y] = m;
  }
  dp1(1, 0);
  dp2(1, 0);
  cout << ans;
  return 0;
}

```