#P4981. Maximum Ancestral Relationships in a Dormitory
Maximum Ancestral Relationships in a Dormitory
Maximum Ancestral Relationships in a Dormitory
In many university male dormitories, there are often chaotic father-child relationships. Consider a dormitory of n distinct individuals. Each individual can have at most one "father" (i.e. a direct parent), but can have many "sons". Moreover, exactly one person has no father (this person is the dorm leader, and as the saying goes, everyone can be a leader).
Under these conditions, in order for any two individuals to be connected by a sequence of direct or indirect father‐child relationships (i.e. for any two distinct individuals, one is an ancestor of the other), the only valid structure is a chain (linear structure). In such a chain, every person (except the leader) has a father, and for any two persons, the earlier one in the chain is directly or indirectly the father of the later one.
The number of ancestral pairs (i.e. pairs (i, j) such that person i is an ancestor of person j) in a chain of n persons is given by the formula:
$\displaystyle \frac{n(n-1)}{2}$
Your task is to compute this maximum number when given n.
inputFormat
The input consists of a single integer n (1 ≤ n ≤ 109), representing the number of people in the dormitory.
outputFormat
Output the maximum number of ancestral (father-child, including indirect) relationships possible in such a dormitory.
sample
1
0