시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 15 3 3 75.000%

문제

You are an employee of the Boxing And Processing Company and you are tasked with distributing boxes in one of the company’s enormous warehouses. At BAPC Ltd., boxes travel by conveyor belt. Two conveyor belts can be merged into one by letting one drop its content onto the other. On the other hand, a belt can be split into two by using a splitter, which sends a specific portion of its input to its first output and the rest to its second output. Normally your splitters are adjustable, being able to distribute its input over its output belts in any conceivable ratio, but in an attempt to cut costs your boss has ordered cheap knock-off splitters which can only distribute its input in a fixed ratio a : b. Instead of arguing with your boss about how you really need some c : d splitters, you decide to make them yourself.

Of course, with your frugal boss, you have to watch your costs. You cannot build your splitter system in such a way that there are boxes that never leave the system. Nor can you use splitters that never receive any boxes. Finally, you cannot use too many a : b splitters in total.

Given the ratios a : b and c : d, construct a network of belts and at most 200 knock-off a : b splitters that has a single global input belt and two global output belts over which the global input is distributed in a ratio c : d.

Note that a splitter of ratio x : y sends exactly x/(x+y) of the incoming boxes to the first output and exactly y/(x+y) of them to the second output.

입력

  • The first line contains two integers 1 ≤ a, b ≤ 109 with a + b ≤ 109 denoting the ratio a : b of your knock-off splitter.
  • The second line contains two integers 1 ≤ c, d ≤ 109 with c + d ≤ 109 denoting the ratio c : d of your desired splitter.

출력

  • The first line contains an integer 1 ≤ n ≤ 200, the number of a : b splitters used.
  • Then follow n lines, the i-th of which contains two integers −2 ≤ li, ri < n.

Here li is the index of the splitter connected to the left output of the i-th splitter, where it deposits a/(a + b) of its input. Similarly ri is the index of the splitter receiving b/(a + b) of the input of the i-th splitter. The splitters are indexed starting from 0. The global input is connected to splitter 0. The special values −1 and −2 for li and ri correspond to the first and second global output, which need to receive c/(c + d) and d/(c + d) of the global input respectively.

Note that you cannot place a splitter in such a way that no box ever reaches it, nor in such a way that a box that passes through it will never reach the output.

If there are multiple possible solutions, you may output any one of them.

예제 입력 1

2 3
3 2

예제 출력 1

1
-2 -1

예제 입력 2

1 2
3 4

예제 출력 2

3
-1 1
2 1
0 -2

예제 입력 3

1 2
1 2

예제 출력 3

3
-2 1
2 0
1 -1