407428: GYM102788 F Spying Game

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Spying Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

It is a well-known fact that most of intelligence information comes from public sources. Following this rule, the Fairy-Tale Kingdom established an analytical unit. The first task of the unit was to map the shipment routes for magic crystals in the neighboring Magic Land. The following information was collected:

  • Crystals can only be shipped from one city to another
  • There is a crystal mine near one of the cities – the source of crystals
  • Crystals are processed in one of the cities – and that is the final destination
  • To make it harder to intercept the trucks, crystal shipment routes often change
  • Only certain roads are used for crystal shipment
  • Each road is used to ship crystals in one direction only
  • The roads are mapped in such a way that it is impossible to return crystals to the city where they have already been, no matter which one of the cities was the origin
  • Any two cities are connected by no more than one road.

The analysts managed to collect information about the number of routes between the source of crystals and other cities. Your task is to plot a possible shipments map. There are $$$n$$$ cities in the Magic Land, with pairs of cities connected by a road. The cities are numbered from $$$1$$$ to $$$n$$$. Only some of roads are used to ship magic crystals. It is known that the crystal mine is located in city $$$m$$$. The number of possible routes from city $$$m$$$ to other cities is represented by vector $$$D$$$, where $$$D[i]$$$ is the number of different routes from city $$$m$$$ to city $$$i$$$.

Write a program that will plot a possible shipments map based on given data ($$$n, m$$$, and vector $$$D$$$). If there are several possible maps, any one of them is acceptable.

Input

The first line in the input file contains integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 60, 1 \le m \le n$$$) separated by a space. The next line contains numbers $$$D[1], D[2], ... D[n]$$$ ($$$0 \le D[i] \le 2^{62}$$$) separated by spaces.

Output

The first line of the output file contains a single positive integer $$$k$$$ – the number of roads used for crystal shipments. Each of the following $$$k$$$ lines contains a pair of numbers – numbers of cities $$$A_i$$$ and $$$B_i$$$ ($$$1 \le A_i, B_i \le n, A_i \ne B_i$$$), which means crystals can be shipped from city $$$A_i$$$ to city $$$B_i$$$.

ExampleInput
5 1
0 1 1 3 3
Output
6
1 2
1 3
1 4
2 4
3 4
4 5

加入题单

算法标签: