#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("0");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
void ppt(long long x) {
  printf("%lld\n", x);
  exit(0);
}
vector<int> mp[500205];
int sz[500205], dp[500205], odd[500205];
long long ans, cnt[500205], ss[500205];
bool hasMatch = 1;
int oddCnt;
void dfs(int x, int pa) {
  sz[x] = 1;
  dp[x] = dp[pa] + 1;
  for (int c : mp[x])
    if (c != pa) {
      dfs(c, x);
      sz[x] += sz[c];
      odd[x] += sz[c] & 1;
      if (sz[c] & 1) oddCnt++;
    }
  odd[x] += sz[x] & 1;
  if (odd[x] > 1) hasMatch = 0;
  if (odd[x] > 3) et();
}
void cal(int x, int pa) {
  sz[x] = 1;
  dp[x] = dp[pa] + 1;
  long long sumGood = 0, sumBad = 0, cntGood = 0, cntBad = 0;
  for (int c : mp[x])
    if (c != pa) {
      cal(c, x);
      sz[x] += sz[c];
      if (sz[c] & 1) {
        ans += ss[c];
        ans += cntGood * ss[c] + sumGood * cnt[c];
        sumBad += ss[c];
        cntBad += cnt[c];
      } else {
        ans += sumBad * cnt[c] + ss[c] * cntBad;
        sumGood += ss[c];
        cntGood += cnt[c];
      }
    }
  if (sz[x] & 1) {
    cnt[x] = cntGood + 1;
    ss[x] = cnt[x] + sumGood;
  } else {
    cnt[x] = cntBad;
    ss[x] = sumBad;
  }
}
vector<int> path;
int X, Y, td = -1, edg[500205];
bool getPath(int x, int pa, int dep) {
  if (odd[x] == 3) {
    if (dep > td) {
      td = dep;
      Y = x;
    }
  }
  bool fg = odd[x] == 3;
  int cc = 0;
  for (int v : mp[x])
    if (v != pa) {
      if (getPath(v, x, dep + 1)) {
        cc++;
        fg = 1;
      }
    }
  if (cc > 1) et();
  if (fg) path.push_back(x);
  return fg;
}
void fmain(int ID) {
  scanf("%d", &n);
  if (n & 1) et();
  for (int i = 0, u, v; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
    mp[v].push_back(u);
  };
  dfs(1, 0);
  if (hasMatch) {
    assert(oddCnt == n / 2);
    cal(1, 0);
    for (int i = 2; i <= n; i++)
      if (sz[i] % 2 == 0) {
        ans += (long long)sz[i] * (n - sz[i]);
      }
    ppt(ans);
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) assert(odd[i] & 1);
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (odd[i] == 3 && dp[i] > dp[X]) X = i;
  getPath(X, 0, 0);
  int N = path.size();
  for (int(i) = 0; (i) < (int)(N - 1); (i)++) {
    edg[i] = min(sz[path[i]], sz[path[i + 1]]) & 1;
  }
  for (int(i) = 0; (i) < (int)(N - 1); (i)++)
    if (edg[i] == 0 && edg[i + 1] == 0) et();
  for (int i = 1; i < N - 1; i++) {
    if (odd[path[i]] == 3) {
      if (edg[i - 1] == 0 || edg[i] == 0) et();
    }
  }
  int len = 0;
  for (int(i) = 0; (i) < (int)(N - 1); (i)++) len += edg[i];
  if (N == 1) {
    cal(X, 0);
    ans = 0;
    path.clear();
    for (int v : mp[X])
      if (sz[v] & 1) {
        path.push_back(v);
      }
    assert(path.size() == 3);
    for (int(j) = 0; (j) < (int)(3); (j)++) {
      long long tmp = 0;
      for (int(jj) = 0; (jj) < (int)(3); (jj)++)
        if (j != jj) tmp += cnt[path[jj]];
      ans += ss[path[j]] * tmp;
    }
    ppt(ans);
  }
  cal(path[0], path[1]);
  cal(path.back(), path[N - 2]);
  ans = 0;
  long long cl = 0, sl = 0, cr = 0, sr = 0;
  for (int v : mp[path[0]])
    if (v != path[1] && (sz[v] & 1)) {
      cl += cnt[v];
      sl += ss[v];
    }
  for (int v : mp[path[N - 1]])
    if (v != path[N - 2] && (sz[v] & 1)) {
      cr += cnt[v];
      sr += ss[v];
    }
  ans = cl * sr + cr * sl + cl * cr * len;
  ppt(ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  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;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("0");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
void ppt(long long x) {
  printf("%lld\n", x);
  exit(0);
}
vector<int> mp[500205];
int sz[500205], dp[500205], odd[500205];
long long ans, cnt[500205], ss[500205];
bool hasMatch = 1;
int oddCnt;
void dfs(int x, int pa) {
  sz[x] = 1;
  dp[x] = dp[pa] + 1;
  for (int c : mp[x])
    if (c != pa) {
      dfs(c, x);
      sz[x] += sz[c];
      odd[x] += sz[c] & 1;
      if (sz[c] & 1) oddCnt++;
    }
  odd[x] += sz[x] & 1;
  if (odd[x] > 1) hasMatch = 0;
  if (odd[x] > 3) et();
}
void cal(int x, int pa) {
  sz[x] = 1;
  dp[x] = dp[pa] + 1;
  long long sumGood = 0, sumBad = 0, cntGood = 0, cntBad = 0;
  for (int c : mp[x])
    if (c != pa) {
      cal(c, x);
      sz[x] += sz[c];
      if (sz[c] & 1) {
        ans += ss[c];
        ans += cntGood * ss[c] + sumGood * cnt[c];
        sumBad += ss[c];
        cntBad += cnt[c];
      } else {
        ans += sumBad * cnt[c] + ss[c] * cntBad;
        sumGood += ss[c];
        cntGood += cnt[c];
      }
    }
  if (sz[x] & 1) {
    cnt[x] = cntGood + 1;
    ss[x] = cnt[x] + sumGood;
  } else {
    cnt[x] = cntBad;
    ss[x] = sumBad;
  }
}
vector<int> path;
int X, Y, td = -1, edg[500205];
bool getPath(int x, int pa, int dep) {
  if (odd[x] == 3) {
    if (dep > td) {
      td = dep;
      Y = x;
    }
  }
  bool fg = odd[x] == 3;
  int cc = 0;
  for (int v : mp[x])
    if (v != pa) {
      if (getPath(v, x, dep + 1)) {
        cc++;
        fg = 1;
      }
    }
  if (cc > 1) et();
  if (fg) path.push_back(x);
  return fg;
}
void fmain(int ID) {
  scanf("%d", &n);
  if (n & 1) et();
  for (int i = 0, u, v; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
    mp[v].push_back(u);
  };
  dfs(1, 0);
  if (hasMatch) {
    assert(oddCnt == n / 2);
    cal(1, 0);
    for (int i = 2; i <= n; i++)
      if (sz[i] % 2 == 0) {
        ans += (long long)sz[i] * (n - sz[i]);
      }
    ppt(ans);
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) assert(odd[i] & 1);
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (odd[i] == 3 && dp[i] > dp[X]) X = i;
  getPath(X, 0, 0);
  int N = path.size();
  for (int(i) = 0; (i) < (int)(N - 1); (i)++) {
    edg[i] = min(sz[path[i]], sz[path[i + 1]]) & 1;
  }
  for (int(i) = 0; (i) < (int)(N - 1); (i)++)
    if (edg[i] == 0 && edg[i + 1] == 0) et();
  for (int i = 1; i < N - 1; i++) {
    if (odd[path[i]] == 3) {
      if (edg[i - 1] == 0 || edg[i] == 0) et();
    }
  }
  int len = 0;
  for (int(i) = 0; (i) < (int)(N - 1); (i)++) len += edg[i];
  if (N == 1) {
    cal(X, 0);
    ans = 0;
    path.clear();
    for (int v : mp[X])
      if (sz[v] & 1) {
        path.push_back(v);
      }
    assert(path.size() == 3);
    for (int(j) = 0; (j) < (int)(3); (j)++) {
      long long tmp = 0;
      for (int(jj) = 0; (jj) < (int)(3); (jj)++)
        if (j != jj) tmp += cnt[path[jj]];
      ans += ss[path[j]] * tmp;
    }
    ppt(ans);
  }
  cal(path[0], path[1]);
  cal(path.back(), path[N - 2]);
  ans = 0;
  long long cl = 0, sl = 0, cr = 0, sr = 0;
  for (int v : mp[path[0]])
    if (v != path[1] && (sz[v] & 1)) {
      cl += cnt[v];
      sl += ss[v];
    }
  for (int v : mp[path[N - 1]])
    if (v != path[N - 2] && (sz[v] & 1)) {
      cr += cnt[v];
      sr += ss[v];
    }
  ans = cl * sr + cr * sl + cl * cr * len;
  ppt(ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}

```