eolymp
bolt
Try our new interface for solving problems
Problems

Christmas Lights Assemby

Christmas Lights Assemby

Peter bought Christmas lights in a do-it-yourself assembly kit. The box contains: \begin{itemize} \item \textbf{2·N} differently colored light bulbs, no two bulbs are the same color; \item \textbf{2·N} sockets for the bulbs; \item enough wires to connect the sockets and bulbs to the electric network. \end{itemize} Each socket has a number of slots for connecting wires. The box comes with \textbf{N} types of sockets. The first type has one slot, the second type has two slots, the third has three, … , and so on. The \textbf{N} type has \textbf{N} slots. There are two sockets of each type. The Christmas lights works when bulbs are screwed into sockets and sockets are wired so that the following conditions are met: \begin{itemize} \item all slots of all sockets must be wired; \item one slot may contain only one wire; \item each wire must be connected to two different sockets; \item two sockets may not be connected by more than one wire. \end{itemize} This task is too difficult for Peter. Help Peter make his Christmas lights work. \InputFile The input file contains an integer \textbf{N} --- the number of socket types (\textbf{1} ≤ \textbf{N} ≤ \textbf{500}). \OutputFile The first line of the output file must contain an integer \textbf{M} --- the number of wires necessary to assemble the kit. The following \textbf{M} lines must each contain two integers separated by spaces ― the numbers of light bulbs screwed into sockets connected by a single wire. The bulbs are numbered from \textbf{1} to \textbf{2·N}. If more than one solution is possible, output any.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
Output example #1
6
1 2
1 3
2 4
1 5
2 6
5 6
Source XIII All-Siberian Programming Contest named after I.V.Pottosin, November 11, 2012