Rules
Sem and Yuri, both over 80 years old, have a peculiar habit of creating rules they believe everyone should follow. Leveraging their societal influence, they attempt to impose these rules universally.
Consider the scenario in a park with n trees, all aligned in a straight line. Each tree can be visualized as a vertical segment with its base at the point (x[i]
; 0) and its top at (x[i]
; h[i]
), where x[i]
represents the tree's position along the line, and h[i]
is its height.
According to Sem and Yuri's latest rule, the top of every tree must be illuminated by a lantern. To achieve this, some trees may need to be trimmed. Specifically, a lantern is positioned at coordinates (x; y), and the rule requires that the line segment from the lantern to the top of each tree must not intersect any other tree. If a tree merely touches this segment, trimming is unnecessary. Even if a tree's height is reduced to zero, it still counts as a tree.
As participants in this challenge, your task is to determine the minimum total length by which the trees need to be trimmed to comply with the rule.
Input Format
The first line contains a single integer n (1 ⩽ n ⩽ 10^5
) — the number of trees in the park.Each of the following n lines contains two integers x[i]
and h[i]
(0 ⩽ x[i]
⩽ 10^9
, 1 ⩽ h[i]
⩽ 1,000) — the position and height of each tree.The next line contains two integers x and y (0 ⩽ x ⩽ 10^9
, 1 ⩽ y ⩽ 1,000) — the coordinates of the lantern.It is guaranteed that the trees are listed in increasing order of their positions, and no tree shares the same position as the lantern.
Output Format
Output a single number — the minimum total length by which the trees need to be trimmed, ensuring an absolute or relative error not exceeding 10^(−6)
.Formally, let your answer be a, and the correct answer be b. Your solution will be accepted if | a − b | / max( 1; |b| ) ⩽ 10^(−6)
.