Problem F
Ski Lifts

The only thing remaining from the old lift system are
-
A line segment can only go between pylons
and if . -
There are two types of pylons, one-way and two-way pylons. The one-way pylons can be connected to at most one other pylon, and the two-way pylons can be connected to at most two other pylons. However, if a two-way pylon
is connected to two other pylons, then they must be on opposite sides of in the -direction. In other words, the two pylons connected to must have different -coordinates. -
Two line segments may not intersect (except that the two line segments incident on a two-way pylon may touch at their endpoints).
What is the maximum number of ski lifts (line segments) you can place under these constraints?
Input
The first line contains one integer
Output
Output the maximum number of ski lift line segments that can be placed.
Sample Input 1 | Sample Output 1 |
---|---|
8 1 0 1 3 0 2 0 1 1 2 1 2 4 1 2 1 2 2 2 3 1 4 3 1 |
4 |
Sample Input 2 | Sample Output 2 |
---|---|
4 0 0 1 100000 1 1 0 99999 1 100000 100000 1 |
2 |