Three-Step Tunnels
Time limit2sMemory limit512 MB
Given n buildings on a line, build at most 5n tunnels so every pair is joined by a monotone path of at most 3 tunnels.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Graph, Implementation
- Solved
- No attempts yet
Problem
A far away city has buildings located along a straight line going from left to right. Because the city is laid out in a straight line, traffic is always a nightmare.
A company has decided to connect the buildings with bidirectional underground tunnels to provide an alternative form of transportation. Each tunnel connects two buildings. To make navigation easy, the company requires that for any two different buildings and , it must be possible to get from to using only tunnels:
- always going in the same direction: left to right if is to the right of , and right to left if is to the left of ; and
- using at most 3 tunnels.
Design a set of tunnels that satisfies these requirements and contains at most tunnels. You do not need to find the smallest possible set.
Input
The only line of input contains a single integer ().
Output
On the first line, print the number of tunnels you propose to build. On each of the next lines, print two distinct integers, the numbers of the buildings connected by that tunnel. The buildings are numbered from 1 to from left to right.
must be less than or equal to . You may print the tunnels in any order. All tunnels must be distinct. For example, you may not include both "1 2" and "2 1".