Tree Average Weight

일부 정점의 차수가 고정된 라벨 트리 중 하나를 균일하게 골라, 간선 기반 가중치의 기댓값의 정수 부분을 구한다.

어려움9트리조합론확률수학아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

Consider a labeled tree with its vertices numbered from 11 to nn.

Let us define the weight of the tree as the sum over all edges uvuv of values usz_uv(u)+vsz_vu(v)u \cdot \mathrm{sz}\_{uv}(u) + v \cdot \mathrm{sz}\_{vu}(v), where sz_vu(v)\mathrm{sz}\_{vu}(v) is the size of subtree containing vv after deleting edge (vu)(vu).

You are given an array aa of size nn. Elements of the array are either integers between 11 and n1n-1 (inclusive), or equal to 1-1. The vv-th element corresponds to the degree of vertex vv. We say that a tree with nn vertices is good if for all vv such that a_v1a\_{v} \ne -1, it is true that the degree of vv equals to a_va\_{v}. In other words, if a_v=1a\_{v} = -1, then vv can have any degree, and otherwise, its degree is fixed and equal to a_va\_{v}.

Let us choose one of the good trees randomly with equal probability. Denote the expected value of the weight of this tree as EE. Find the integer part of EE.

입력

The first line of input contains an integer nn: the size of the tree (2n1062 \le n \le 10^{6}).

The second line of input contains an array of size nn. Each element of the array is either an integer between 11 and n1n-1 (fixed degree), or equal to 1-1 (arbitrary degree). It is guaranteed that the sum of absolute values of elements is not greater than 2n22n-2.

출력

Print the integer part of EE.