PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000079. Bao phủ một đoạn (Interval Cover)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bao phủ một đoạn (Interval Cover)

Interval Cover

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Given a target real interval [A,B][A,B], where A<BA<B, and nn closed real intervals [li,ri][l_i,r_i] indexed from 00, select as few of them as possible so their union covers all of [A,B][A,B]. Selected intervals may extend beyond the target. Output impossible if covering is infeasible; otherwise output an optimal count and the original zero-based indices. Any optimal selection is acceptable.

Input

The first line contains real numbers A,BA,B. The second line contains nn. Each of the next nn lines contains real numbers li,ril_i,r_i, written as decimals.

Output

Print impossible if no cover exists. Otherwise print the minimum number kk of intervals, followed by kk distinct zero-based interval indices in any order.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; −106≤A<B≤106-10^6\le A<B\le10^6; −106≤li<ri≤106-10^6\le l_i<r_i\le10^6.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le 1500; −106≤A<B≤106-10^6\le A<B\le10^6; −106≤li<ri≤106-10^6\le l_i<r_i\le10^6.
  • Subtask 3 (50 points): 1≤n≤1041\le n\le10^4; −106≤A<B≤106-10^6\le A<B\le10^6; −106≤li<ri≤106-10^6\le l_i<r_i\le10^6.

Examples

Input

0 10
4
-1 4
3 8
8 12
2 6

Output

3
0 1 2

Explanation

Intervals 00, 11, and 22 cover [0,4][0,4], then [3,8][3,8], then [8,12][8,12], so they cover [0,10][0,10]. No pair can both cover the target start and reach its end. Thus three is optimal.