#include <bits/stdc++.h>
using namespace std;
int const MAX = 5e5 + 41;
int n;
vector<int> e[MAX];
long long ans;
int col[MAX];
int dc[MAX];
void dfs0(int x, int p = -1) {
  if (p == -1) e[x].push_back(p);
  for (int i = 0; i <= (int)e[x].size() - 1; i++) {
    int y = e[x][i];
    if (y == p) {
      swap(e[x][i], e[x][(int)e[x].size() - 1]);
      break;
    }
  }
  e[x].insert(e[x].begin(), p);
  for (int y : e[x]) {
    if (y == p) continue;
    col[y] = 1 - col[x];
    dfs0(y, x);
  }
  dc[x] = 1;
  for (int y : e[x]) {
    if (y == p) continue;
    dc[x] += dc[y];
  }
}
int const MASK = (1 << 3);
struct State {
  int mask[MASK];
  State() { memset(mask, 0, sizeof(mask)); };
  State(const State &a) { memcpy(mask, a.mask, sizeof(mask)); }
  void print() {
    for (int i = 0; i <= MASK - 1; i++) {
      if (mask[i]) {
        while (false) {
        };
      }
    }
    while (false) {
    };
  }
};
vector<State> dp[MAX];
vector<State> ds[MAX];
State d[MAX];
int bit(int m, int i) { return (1 & (m >> i)); }
int qbit(int m) { return __builtin_popcount(m); }
void dfs1(int x, int p = -1) {
  int k = (int)e[x].size();
  dp[x].resize(k);
  dp[x][0].mask[0] = 1;
  for (int i = 0; i <= k - 2; i++) {
    int y = e[x][i];
    if (y == p) {
      dp[x][i + 1] = State(dp[x][i]);
      continue;
    }
    dfs1(y, x);
    for (int mx = 0; mx <= MASK - 1; mx++) {
      for (int my = 0; my <= MASK - 1; my++) {
        if (!d[y].mask[my]) continue;
        if (!dp[x][i].mask[mx]) continue;
        long long ways = dp[x][i].mask[mx] * d[y].mask[my];
        if (qbit(mx & 3) + qbit(my & 3) > 1) continue;
        int nm = ((mx | my) & 3);
        if (nm) {
          if (bit(my, 2)) {
            nm |= mx;
          } else {
            if (bit(mx, 2)) continue;
            nm |= (1 << 2);
          }
          dp[x][i + 1].mask[nm] += ways;
        } else {
          if (!bit(mx, 2) && !bit(my, 2)) {
            int nm1 = (1 << 2);
            dp[x][i + 1].mask[nm1] += ways;
            int nm2 = (1 << (col[y]));
            dp[x][i + 1].mask[nm2] += ways;
          } else {
            if (!bit(my, 2)) {
              nm = (1 << col[y]) | (1 << 2);
            } else {
              nm = mx;
            }
            dp[x][i + 1].mask[nm] += ways;
          }
        }
      }
    }
  }
  reverse(e[x].begin(), e[x].end());
  ds[x].resize(k);
  ds[x][0].mask[0] = 1;
  for (int i = 0; i <= k - 2; i++) {
    int y = e[x][i];
    if (y == p) {
      ds[x][i + 1] = State(ds[x][i]);
      continue;
    }
    for (int mx = 0; mx <= MASK - 1; mx++) {
      for (int my = 0; my <= MASK - 1; my++) {
        if (!d[y].mask[my]) continue;
        if (!ds[x][i].mask[mx]) continue;
        int ways = ds[x][i].mask[mx] * d[y].mask[my];
        if (qbit(mx & 3) + qbit(my & 3) > 1) continue;
        int nm = ((mx | my) & 3);
        if (nm) {
          if (bit(my, 2)) {
            nm |= mx;
          } else {
            if (bit(mx, 2)) continue;
            nm |= (1 << 2);
          }
          ds[x][i + 1].mask[nm] += ways;
        } else {
          if (!bit(mx, 2) && !bit(my, 2)) {
            int nm1 = (1 << 2);
            ds[x][i + 1].mask[nm1] += ways;
            int nm2 = (1 << (col[y]));
            ds[x][i + 1].mask[nm2] += ways;
          } else {
            if (!bit(my, 2)) {
              nm = (1 << col[y]) | (1 << 2);
            } else {
              nm = mx;
            }
            ds[x][i + 1].mask[nm] += ways;
          }
        }
      }
    }
  }
  reverse(e[x].begin(), e[x].end());
  reverse(ds[x].begin(), ds[x].end());
  d[x] = State(dp[x][k - 1]);
}
map<pair<pair<int, int>, pair<int, int> >, long long> all;
int dup[MAX][MASK];
void dfs2(int x) {
  int k = (int)e[x].size();
  for (int mask = 0; mask <= MASK - 1; mask++) {
    for (int i = 1; i <= k - 2; i++) {
      int y = e[x][i];
      for (int m1 = 0; m1 <= MASK - 1; m1++) {
        for (int m2 = 0; m2 <= MASK - 1; m2++) {
          if (!dp[x][i].mask[m1]) continue;
          if (!ds[x][i].mask[m2]) continue;
          int ways = dp[x][i].mask[m1] * ds[x][i].mask[m2] * dup[x][mask];
          if (qbit(mask & 3) + qbit(m1 & 3) + qbit(m2 & 3) > 1) continue;
          if (qbit(mask & 4) + qbit(m1 & 4) + qbit(m2 & 4) > 1) continue;
          int child = qbit((mask | m1 | m2) & 3);
          int mt = bit(mask | m1 | m2, 2);
          if (child) {
            if (!mt) {
              int nm = (mask | m1 | m2);
              nm |= (1 << 2);
              dup[y][nm] += ways;
            } else {
              int nm = (mask | m1 | m2);
              nm ^= (1 << 2);
              dup[y][nm] += ways;
            }
          } else {
            if (!mt) {
              int nm = (1 << 2);
              dup[y][nm] += ways;
              nm = (1 << col[x]);
              dup[y][nm] += ways;
            } else {
              dup[y][0] += ways;
            }
          }
          if (child + (1 - mt) < 2) {
            int mx = ((mask | m1 | m2) & 3);
            if (!mt) {
              assert(mx == 0);
              mx |= (1 << col[x]);
            }
            for (int my = 0; my <= MASK - 1; my++) {
              if (!d[y].mask[my]) continue;
              int c = qbit(my & 3);
              int m = bit(my, 2);
              if (c + (1 - m) >= 2) continue;
              int my1 = (my & 3);
              if (!m) {
                assert(my1 == 0);
                my1 |= (1 << col[y]);
              }
              long long ways1 = (long long)ways * d[y].mask[my];
              if (!ways1) continue;
              if (qbit(mx) != qbit(my1)) continue;
              if (mx == my1 && mx == 0) {
                assert(ways1 == 1);
                ways1 *= (long long)dc[y] * (n - dc[y]);
              }
              ans += ways1;
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= (int)e[x].size() - 2; i++) {
    int y = e[x][i];
    dfs2(y);
  }
}
void solve() {
  dfs0(1);
  dfs1(1);
  dup[1][0] = 1;
  dfs2(1);
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  solve();
  return 0;
}

### Prompt

Please formulate a CPP solution to 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;
int const MAX = 5e5 + 41;
int n;
vector<int> e[MAX];
long long ans;
int col[MAX];
int dc[MAX];
void dfs0(int x, int p = -1) {
  if (p == -1) e[x].push_back(p);
  for (int i = 0; i <= (int)e[x].size() - 1; i++) {
    int y = e[x][i];
    if (y == p) {
      swap(e[x][i], e[x][(int)e[x].size() - 1]);
      break;
    }
  }
  e[x].insert(e[x].begin(), p);
  for (int y : e[x]) {
    if (y == p) continue;
    col[y] = 1 - col[x];
    dfs0(y, x);
  }
  dc[x] = 1;
  for (int y : e[x]) {
    if (y == p) continue;
    dc[x] += dc[y];
  }
}
int const MASK = (1 << 3);
struct State {
  int mask[MASK];
  State() { memset(mask, 0, sizeof(mask)); };
  State(const State &a) { memcpy(mask, a.mask, sizeof(mask)); }
  void print() {
    for (int i = 0; i <= MASK - 1; i++) {
      if (mask[i]) {
        while (false) {
        };
      }
    }
    while (false) {
    };
  }
};
vector<State> dp[MAX];
vector<State> ds[MAX];
State d[MAX];
int bit(int m, int i) { return (1 & (m >> i)); }
int qbit(int m) { return __builtin_popcount(m); }
void dfs1(int x, int p = -1) {
  int k = (int)e[x].size();
  dp[x].resize(k);
  dp[x][0].mask[0] = 1;
  for (int i = 0; i <= k - 2; i++) {
    int y = e[x][i];
    if (y == p) {
      dp[x][i + 1] = State(dp[x][i]);
      continue;
    }
    dfs1(y, x);
    for (int mx = 0; mx <= MASK - 1; mx++) {
      for (int my = 0; my <= MASK - 1; my++) {
        if (!d[y].mask[my]) continue;
        if (!dp[x][i].mask[mx]) continue;
        long long ways = dp[x][i].mask[mx] * d[y].mask[my];
        if (qbit(mx & 3) + qbit(my & 3) > 1) continue;
        int nm = ((mx | my) & 3);
        if (nm) {
          if (bit(my, 2)) {
            nm |= mx;
          } else {
            if (bit(mx, 2)) continue;
            nm |= (1 << 2);
          }
          dp[x][i + 1].mask[nm] += ways;
        } else {
          if (!bit(mx, 2) && !bit(my, 2)) {
            int nm1 = (1 << 2);
            dp[x][i + 1].mask[nm1] += ways;
            int nm2 = (1 << (col[y]));
            dp[x][i + 1].mask[nm2] += ways;
          } else {
            if (!bit(my, 2)) {
              nm = (1 << col[y]) | (1 << 2);
            } else {
              nm = mx;
            }
            dp[x][i + 1].mask[nm] += ways;
          }
        }
      }
    }
  }
  reverse(e[x].begin(), e[x].end());
  ds[x].resize(k);
  ds[x][0].mask[0] = 1;
  for (int i = 0; i <= k - 2; i++) {
    int y = e[x][i];
    if (y == p) {
      ds[x][i + 1] = State(ds[x][i]);
      continue;
    }
    for (int mx = 0; mx <= MASK - 1; mx++) {
      for (int my = 0; my <= MASK - 1; my++) {
        if (!d[y].mask[my]) continue;
        if (!ds[x][i].mask[mx]) continue;
        int ways = ds[x][i].mask[mx] * d[y].mask[my];
        if (qbit(mx & 3) + qbit(my & 3) > 1) continue;
        int nm = ((mx | my) & 3);
        if (nm) {
          if (bit(my, 2)) {
            nm |= mx;
          } else {
            if (bit(mx, 2)) continue;
            nm |= (1 << 2);
          }
          ds[x][i + 1].mask[nm] += ways;
        } else {
          if (!bit(mx, 2) && !bit(my, 2)) {
            int nm1 = (1 << 2);
            ds[x][i + 1].mask[nm1] += ways;
            int nm2 = (1 << (col[y]));
            ds[x][i + 1].mask[nm2] += ways;
          } else {
            if (!bit(my, 2)) {
              nm = (1 << col[y]) | (1 << 2);
            } else {
              nm = mx;
            }
            ds[x][i + 1].mask[nm] += ways;
          }
        }
      }
    }
  }
  reverse(e[x].begin(), e[x].end());
  reverse(ds[x].begin(), ds[x].end());
  d[x] = State(dp[x][k - 1]);
}
map<pair<pair<int, int>, pair<int, int> >, long long> all;
int dup[MAX][MASK];
void dfs2(int x) {
  int k = (int)e[x].size();
  for (int mask = 0; mask <= MASK - 1; mask++) {
    for (int i = 1; i <= k - 2; i++) {
      int y = e[x][i];
      for (int m1 = 0; m1 <= MASK - 1; m1++) {
        for (int m2 = 0; m2 <= MASK - 1; m2++) {
          if (!dp[x][i].mask[m1]) continue;
          if (!ds[x][i].mask[m2]) continue;
          int ways = dp[x][i].mask[m1] * ds[x][i].mask[m2] * dup[x][mask];
          if (qbit(mask & 3) + qbit(m1 & 3) + qbit(m2 & 3) > 1) continue;
          if (qbit(mask & 4) + qbit(m1 & 4) + qbit(m2 & 4) > 1) continue;
          int child = qbit((mask | m1 | m2) & 3);
          int mt = bit(mask | m1 | m2, 2);
          if (child) {
            if (!mt) {
              int nm = (mask | m1 | m2);
              nm |= (1 << 2);
              dup[y][nm] += ways;
            } else {
              int nm = (mask | m1 | m2);
              nm ^= (1 << 2);
              dup[y][nm] += ways;
            }
          } else {
            if (!mt) {
              int nm = (1 << 2);
              dup[y][nm] += ways;
              nm = (1 << col[x]);
              dup[y][nm] += ways;
            } else {
              dup[y][0] += ways;
            }
          }
          if (child + (1 - mt) < 2) {
            int mx = ((mask | m1 | m2) & 3);
            if (!mt) {
              assert(mx == 0);
              mx |= (1 << col[x]);
            }
            for (int my = 0; my <= MASK - 1; my++) {
              if (!d[y].mask[my]) continue;
              int c = qbit(my & 3);
              int m = bit(my, 2);
              if (c + (1 - m) >= 2) continue;
              int my1 = (my & 3);
              if (!m) {
                assert(my1 == 0);
                my1 |= (1 << col[y]);
              }
              long long ways1 = (long long)ways * d[y].mask[my];
              if (!ways1) continue;
              if (qbit(mx) != qbit(my1)) continue;
              if (mx == my1 && mx == 0) {
                assert(ways1 == 1);
                ways1 *= (long long)dc[y] * (n - dc[y]);
              }
              ans += ways1;
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= (int)e[x].size() - 2; i++) {
    int y = e[x][i];
    dfs2(y);
  }
}
void solve() {
  dfs0(1);
  dfs1(1);
  dup[1][0] = 1;
  dfs2(1);
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  solve();
  return 0;
}

```