This page is still under construction.

Parts of this page are still being built. What you see may change.

School Democracy

Time limit2sMemory limit512 MB

Summary
Partition the classes into consecutive groups of size between l and r, and maximize the total difference between elected boys and girls, where each group elects the side with more votes or both on a tie.
Level

Medium7 of 10

Topics
Dynamic programming, Prefix sum, Sliding window, Greedy
Solved
No attempts yet

Problem

School number 932 is holding an election for the school council. The election works as follows. The vice principal takes the list of all classes in the school and splits them into groups. Each group consists of one or more classes that are consecutive in the list, and every class ends up in exactly one group.

Each group of classes nominates two candidates to the school council, one boy and one girl. Then every student votes for one of the two candidates nominated by their group. Boys always vote for the boy candidate, and girls always vote for the girl candidate. Votes are counted independently in each group. The candidate with the most votes in their group is elected to the school council. If the votes are tied, both candidates nominated by that group are elected to the school council.

Suppose the election sends BB boys and GG girls to the school council. From past years' experience, the vice principal believes the council works more efficiently the larger the difference B−GB-G between the number of boys and the number of girls. This value can be negative, and the vice principal wants to maximize the value itself, not its absolute value. For example, between B=2B = 2, G=5G = 5, where B−G=−3B - G = -3, and B=3B = 3, G=4G = 4, where B−G=−1B - G = -1, the second option is preferable.

The school has nn classes in total, and the vice principal has already prepared their list. Now he has to split them into groups. A group cannot contain fewer than ll classes, or the council will be very large. At the same time, a group cannot contain more than rr classes, or the students will not be able to agree on the candidates to nominate. Recall that each group must consist of classes that are consecutive in the vice principal's list.

Help the vice principal find the optimal split into groups by his judgment.

Input

The first line of the input contains three integers nn, ll, and rr (1≤n≤100 0001 \le n \le 100\,000, 1≤l≤r≤n1 \le l \le r \le n): the number of classes in the school and the minimum and maximum allowed number of classes in one group, respectively. The following nn lines contain two integers bib_i and gig_i each (1≤bi,gi≤10 0001 \le b_i, g_i \le 10\,000): the number of boys and girls in the ii-th class, respectively.

Output

In the first line, print the integer xx, the number of groups in the optimal split by the vice principal's judgment. In the following xx lines, print two integers sis_i and fif_i (1≤si≤fi≤n1 \le s_i \le f_i \le n). This means that the ii-th group should include classes from the sis_i-th to the fif_i-th, inclusive. The groups may be printed in any order. Every class must be in exactly one group.

At least one split satisfying all constraints is guaranteed to exist. If there are several optimal answers, print any of them.

Examples1

  1. Example 1

    Input
    5 1 2
    7 5
    10 1
    2 3
    2 6
    4 3
    
    Expected output
    4
    1 1
    2 3
    4 4
    5 5