#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T>
inline bool rd(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void pt(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) pt(x / 10);
  putchar(x % 10 + '0');
}
using namespace std;
const int N = 200100;
const int mod = 1e9 + 7;
int n;
vector<int> G[N];
vector<long long> D[N], P[N];
long long down[N], up[N];
long long go[N];
void mul(long long &x, long long y) {
  x *= y;
  x %= mod;
}
void dfs_down(int u, int fa) {
  down[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) {
      D[u].push_back(1);
      P[u].push_back(1);
      continue;
    }
    dfs_down(v, u);
    mul(down[u], down[v] + 1);
    D[u].push_back(down[v] + 1);
    P[u].push_back(down[v] + 1);
  }
  for (int i = 1; i < D[u].size(); i++) mul(D[u][i], D[u][i - 1]);
  for (int i = (int)P[u].size() - 2; i >= 0; i--) mul(P[u][i], P[u][i + 1]);
}
void dfs_up(int u, int fa, long long way) {
  up[u] = way;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) continue;
    long long tmp = way;
    if (i && i < (int)D[u].size()) mul(tmp, D[u][i - 1]);
    if (i + 1 < P[u].size()) mul(tmp, P[u][i + 1]);
    dfs_up(v, u, tmp + 1);
  }
}
int main() {
  rd(n);
  for (int i = 2, x; i <= n; i++) {
    rd(x);
    G[x].push_back(i);
    G[i].push_back(x);
  }
  dfs_down(1, 1);
  dfs_up(1, 1, 1);
  for (int i = 1; i <= n; i++) pt(down[i] * up[i] % mod), putchar(' ');
  return 0;
}

### Prompt

Your task is to create a cpp solution to the following problem:

The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive.

All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that the citizens are happy about road improvement if the path from the capital located in city x to any other city contains at most one bad road.

Your task is — for every possible x determine the number of ways of improving the quality of some roads in order to meet the citizens' condition. As those values can be rather large, you need to print each value modulo 1 000 000 007 (109 + 7).

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 2·105) — the number of cities in the country. Next line contains n - 1 positive integers p2, p3, p4, ..., pn (1 ≤ pi ≤ i - 1) — the description of the roads in the country. Number pi means that the country has a road connecting city pi and city i. 

Output

Print n integers a1, a2, ..., an, where ai is the sought number of ways to improve the quality of the roads modulo 1 000 000 007 (109 + 7), if the capital of the country is at city number i.

Examples

Input

3
1 1


Output

4 3 3

Input

5
1 2 3 4


Output

5 8 9 8 5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T>
inline bool rd(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void pt(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) pt(x / 10);
  putchar(x % 10 + '0');
}
using namespace std;
const int N = 200100;
const int mod = 1e9 + 7;
int n;
vector<int> G[N];
vector<long long> D[N], P[N];
long long down[N], up[N];
long long go[N];
void mul(long long &x, long long y) {
  x *= y;
  x %= mod;
}
void dfs_down(int u, int fa) {
  down[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) {
      D[u].push_back(1);
      P[u].push_back(1);
      continue;
    }
    dfs_down(v, u);
    mul(down[u], down[v] + 1);
    D[u].push_back(down[v] + 1);
    P[u].push_back(down[v] + 1);
  }
  for (int i = 1; i < D[u].size(); i++) mul(D[u][i], D[u][i - 1]);
  for (int i = (int)P[u].size() - 2; i >= 0; i--) mul(P[u][i], P[u][i + 1]);
}
void dfs_up(int u, int fa, long long way) {
  up[u] = way;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) continue;
    long long tmp = way;
    if (i && i < (int)D[u].size()) mul(tmp, D[u][i - 1]);
    if (i + 1 < P[u].size()) mul(tmp, P[u][i + 1]);
    dfs_up(v, u, tmp + 1);
  }
}
int main() {
  rd(n);
  for (int i = 2, x; i <= n; i++) {
    rd(x);
    G[x].push_back(i);
    G[i].push_back(x);
  }
  dfs_down(1, 1);
  dfs_up(1, 1, 1);
  for (int i = 1; i <= n; i++) pt(down[i] * up[i] % mod), putchar(' ');
  return 0;
}

```