Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1,  a2,  ...,  an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i  -  1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you.

The first line contains integers n, w, h (1  ≤ n ≤ 5000, 1 ≤ w,  h  ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi,  hi ≤ 106).

In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
)

type Envelope struct {
	Index  int
	Height int
	Width  int
}

type Sorter struct {
	Envelopes []*Envelope
}

func (s Sorter) Len() int {
	return len(s.Envelopes)
}
func (s Sorter) Swap(i, j int) {
	s.Envelopes[i], s.Envelopes[j] = s.Envelopes[j], s.Envelopes[i]
}

func (s Sorter) Less(i, j int) bool {
	if s.Envelopes[i].Height == s.Envelopes[j].Height {
		return s.Envelopes[i].Width < s.Envelopes[j].Width
	}
	return s.Envelopes[i].Height < s.Envelopes[j].Height
}

func main() {

	dp := [5000]int{}
	prev := [5000]int{}
	max := -1
	maxIndex := -1

	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	envs := make([]*Envelope, 0, 5000)
	var nn, n, w, h int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &w, &h)
	for i := 0; i < n; i++ {
		e := Envelope{Index: i + 1}
		fmt.Fscanf(reader, "%d %d\n", &e.Width, &e.Height)
		if e.Width > w && e.Height > h {
			envs = append(envs, &e)
			nn++
		}
	}

	sort.Sort(Sorter{envs})
	for i := 0; i < nn; i++ {
		dp[i], prev[i] = 1, -1
		e0 := envs[i]
		for j := 0; j < i; j++ {
			e1 := envs[j]
			if e1.Height == e0.Height {
				break
			}
			if e1.Width < e0.Width && dp[j]+1 > dp[i] {
				dp[i] = dp[j] + 1
				prev[i] = j
			}
		}
		if max < dp[i] {
			max = dp[i]
			maxIndex = i
		}
	}

	if max == -1 {
		fmt.Printf("0")
	} else {
		solution := make([]int, 0, 5000)
		fmt.Printf("%d\n", max)
		for maxIndex != -1 {
			solution = append(solution, envs[maxIndex].Index)
			maxIndex = prev[maxIndex]
		}
		for i := len(solution) - 1; i >= 0; i-- {
			fmt.Printf("%d ", solution[i])
		}
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, w, h := readThreeNums(reader)
	envs := make([][]int, n)
	for i := 0; i < n; i++ {
		envs[i] = readNNums(reader, 2)
	}
	res := solve(n, w, h, envs)

	var buf bytes.Buffer

	buf.WriteString(fmt.Sprintf("%d\n", len(res)))

	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n, w, h int, envs [][]int) []int {
	items := make([]Envelope, n)
	var H int
	for i := 0; i < n; i++ {
		items[i] = Envelope{envs[i][0], envs[i][1], i}
		H = max(H, envs[i][1])
	}

	sort.Sort(Envelopes(items))
	H++
	arr := make([]int, 2*H)

	update := func(p int, v int) {
		p += H
		arr[p] = v
		for p > 0 {
			arr[p>>1] = max(arr[p], arr[p^1])
			p >>= 1
		}
	}

	get := func(l, r int) int {
		var res int
		l += H
		r += H

		for l < r {
			if l&1 == 1 {
				res = max(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = max(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	dp := make([]int, n+1)
	var best int
	for i := 0; i < n; i++ {
		cur := items[i]
		if cur.width <= w {
			break
		}

		if cur.height <= h {
			continue
		}

		cnt := get(cur.height+1, H)
		dp[i] = cnt + 1
		update(cur.height, cnt+1)
		best = max(best, cnt+1)
	}

	if best == 0 {
		return nil
	}

	cur := -1
	for i := n - 1; i >= 0; i-- {
		if dp[i] == best {
			cur = i
			break
		}
	}
	res := make([]int, 0, best)
	res = append(res, items[cur].index+1)

	for i := cur - 1; i >= 0; i-- {
		if dp[i]+1 == best && items[i].width > items[cur].width && items[i].height > items[cur].height {
			best--
			cur = i
			res = append(res, items[cur].index+1)
		}
	}
	//reverse(res)

	return res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Envelope struct {
	width  int
	height int
	index  int
}

type Envelopes []Envelope

func (ps Envelopes) Len() int {
	return len(ps)
}

func (ps Envelopes) Less(i, j int) bool {
	return ps[i].width > ps[j].width || ps[i].width == ps[j].width && ps[i].height < ps[j].height
}

func (ps Envelopes) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type envelope struct {
	w, h, index, len, child int
}

func solve() {
	n := readInt()
	w := readInt()
	h := readInt()

	e := make([]envelope, 0, n)
	for i := 0; i < n; i++ {
		ew := readInt()
		eh := readInt()
		if ew <= w || eh <= h {
			// card won't fit, ignore it
			continue
		}
		e = append(e, envelope{ew, eh, i + 1, 0, -1})
	}

	if len(e) == 0 {
		fmt.Println(0)
		return
	}

	// Sort by area
	sort.Slice(e, func(i, j int) bool {
		ai := uint64(e[i].w) * uint64(e[i].h)
		aj := uint64(e[j].w) * uint64(e[j].h)
		return ai < aj
	})

	maxlen := 0
	for inner, v_inner := range e {
		for outer := inner; outer < len(e); outer++ {
			if v_inner.w >= e[outer].w || v_inner.h >= e[outer].h {
				// doesn't fit: too wide or too tall
				continue
			}
			if v_inner.len+1 > e[outer].len {
				e[outer].len = v_inner.len + 1
				e[outer].child = inner
			}
			maxlen = max(e[outer].len, maxlen)
		}
	}
	fmt.Println(maxlen + 1)

	lastidx := len(e)
	for i := len(e) - 1; i >= 0; i-- {
		if e[i].len == maxlen {
			lastidx = i
			break
		}
	}
	if lastidx == len(e) {
		panic("huh?")
	}

	a := make([]int, maxlen+1)
	for ; maxlen >= 0; maxlen-- {
		a[maxlen] = e[lastidx].index
		lastidx = e[lastidx].child
	}
	space := ""
	for _, v := range a {
		fmt.Printf("%v%v", space, v)
		space = " "
	}
	fmt.Println()
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var in = bufio.NewScanner(os.Stdin)

var n, w, h, max, maxi, elen int
var e [5001][3]int
var dep [5001]int
var prev [5001]int
var ret [5001]int

type Matrix [5001][3]int

func init() {
  in.Split(bufio.ScanWords)
  for i := range dep {
    dep[i] = 1
  }

  for i := range prev {
    prev[i] = -1
  }
}

func (m Matrix) Len() int           { return elen }
func (m Matrix) Less(i, j int) bool { return m[i][0] < m[j][0] }
func (m *Matrix) Swap(i, j int)     { m[i], m[j] = m[j], m[i] }

func main() {
  n, w, h = readInt(), readInt(), readInt()

  for i := 0; i < n; i++ {
    tw, th := readInt(), readInt()
    if tw > w && th > h {
      e[elen][0], e[elen][1], e[elen][2] = tw, th, i
      elen++
    }
  }

  if elen == 0 {
    fmt.Println("0")
    return
  }

  m := Matrix(e)
  sort.Sort(&m)

  for i := 1; i < elen; i++ {
    for j := 0; j < i; j++ {
      if m[i][0] > m[j][0] && m[i][1] > m[j][1] && dep[i] < dep[j]+1 {
        dep[i] = dep[j] + 1
        prev[i] = j
      }
    }
  }

  for i := 0; i < elen; i++ {
    if max < dep[i] {
      max = dep[i]
      maxi = i
    }
  }

  i := maxi
  j := 0
  for {
    ret[j] = m[i][2]
    i = prev[i]
    if i == -1 {
      break
    }
    j++
  }

  fmt.Printf("%d\n", max)
  for i := j; i >= 0; i-- {
    fmt.Printf("%d ", ret[i]+1)
  }
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

type envelope struct {
	w, h int
}

func readEnvs(n, w, h int) ([]envelope, map[envelope]int) {
	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	return envs, envIdxMap
}

func findlis(envs []envelope) []int {
	lis := make([]int, len(envs))
	parent := make([]int, len(envs))

	globalMaxLisIdx := 0

	for i := 0; i < len(envs); i++ {
		maxLis := lis[i]
		maxLisIdx := -1
		for j := 0; j < i; j++ {
			if envs[i].w > envs[j].w && envs[i].h > envs[j].h && lis[j] >= maxLis {
				maxLis = lis[j]
				maxLisIdx = j
			}
		}

		lis[i] = maxLis + 1
		parent[i] = maxLisIdx

		if lis[globalMaxLisIdx] <= lis[i] {
			globalMaxLisIdx = i
		}
	}

	idxList := make([]int, 0)
	for idx := globalMaxLisIdx; idx != -1; {
		idxList = append(idxList, idx)
		idx = parent[idx]
	}

	return idxList
}

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	envs, envIdxMap := readEnvs(n, w, h)

	if len(envs) == 0 {
		printf("0\n")
		return
	}

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		return envs[i].w < envs[j].w || ((envs[i].w == envs[j].w) && envs[i].h <= envs[j].h)
		//return int64(envs[i].w)*int64(envs[i].h) < int64(envs[j].w)*int64(envs[j].h) && envs[i].w <= envs[j].w && envs[i].h <= envs[j].h
	})

	if debug {
		printf("%v\n", envs)
	}

	idxList := findlis(envs)

	printf("%d\n", len(idxList))
	for i := len(idxList) - 1; i >= 0; i-- {
		if debug {
			printf("%d (%v) ", envIdxMap[envs[idxList[i]]]+1, envs[idxList[i]])
		} else {
			printf("%d ", envIdxMap[envs[idxList[i]]]+1)
		}
		if i == 0 {
			printf("\n")
		}
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"sort"
)

type envelope struct {
	w, h, i int
}

type input struct {
	n int
	w, h int
	es []envelope
}

type output struct {
	ary []int
	memo []int
	crumbs []int
	max_len, max_idx int
}

func read_input() *input {
	result := &input{}
	r := bufio.NewReader(os.Stdin)

	fmt.Fscanf(r, "%d %d %d\n", &result.n, &result.w, &result.h)

	result.es = make([]envelope, result.n)

	for i := 0; i < result.n; i++ {
		result.es[i].i = i + 1
		fmt.Fscanf(r, "%d %d\n", &result.es[i].w, &result.es[i].h)
	}

	return result
}

func process_input(inp *input) *output {
	sort.Sort(ByArea(inp.es))

	out := &output{}
	out.max_len, out.max_idx = 0, -1
 	out.memo = make([]int, inp.n)

	// initialize the memo, taking into account that valid envelopes must be > postcard's dimensions
	for i := range out.memo {
		if inp.es[i].w > inp.w && inp.es[i].h > inp.h {
			out.memo[i] = 1
			if out.max_len == 0 {
				out.max_len = 1
				out.max_idx = i
			}
		}
 	}

	out.crumbs = make([]int, inp.n)
	for i := range out.crumbs {
		out.crumbs[i] = -1
	}

 	for i := 0; i < inp.n; i++ {
 		for j := 0; j < inp.n; j++ {
			if i == j {
				// we are not interested in link to ourselves
				continue
			}

			// ignore too small an envelope
			if inp.es[i].w <= inp.w || inp.es[i].h <= inp.h {
				continue
			}

			if inp.es[i].w < inp.es[j].w && inp.es[i].h < inp.es[j].h {
				// i -> j
				if out.memo[j] < out.memo[i] + 1 {
					out.memo[j] = out.memo[i] + 1
					out.crumbs[j] = i

					if out.memo[j] > out.max_len {
						out.max_len = out.memo[j]
						out.max_idx = j
					}
				}
			}
		}
	}

	out.ary = make([]int, out.max_len)
	for i, idx := out.max_len - 1, out.max_idx; i >= 0; i-- {
		out.ary[i] = inp.es[idx].i
		idx        = out.crumbs[idx]
	}

	return out
}

// ByArea implements sort.Interface for []envelope based on the area of the envelope.
type ByArea []envelope

func (a ByArea) Len() int           { return len(a) }
func (a ByArea) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByArea) Less(i, j int) bool { return int64(a[i].w) * int64(a[i].h) < int64(a[j].w) * int64(a[j].h) }

func main() {
	i := read_input()

	out := process_input(i)
	fmt.Printf("%d\n", out.max_len)
	if (out.max_len != 0) {
		idx, l := 0, len(out.ary)
		fmt.Printf("%d", out.ary[idx])
		for idx = 1; idx < l; idx++ {
			fmt.Printf(" %d", out.ary[idx])
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func Sol4D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	type pair struct{ w, h int }
	env := make([]pair, n+1)
	for i := range env {
		Fscan(in, &env[i].w, &env[i].h)
	}

	next := make([]int, n+1)
	for i := range next {
		next[i] = -1
	}
	dp := make([]int, n+1)
	var dfs func(v int) int
	dfs = func(v int) int {
		if dp[v] == 0 {
			for w, e := range env {
				if env[v].w < e.w && env[v].h < e.h {
					if dpw := dfs(w) + 1; dpw > dp[v] {
						dp[v] = dpw
						next[v] = w
					}
				}
			}
		}
		return dp[v]
	}
	Fprintln(out, dfs(0))
	for v := next[0]; v != -1; v = next[v] {
		Fprint(out, v, " ")
	}
}

func main() {
	Sol4D(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
	"strconv"
	"errors"
	"sort"
	"runtime"
)

type env struct {
	w, h, i int
}

func (e *env) ft(ee *env) bool {
	return e.w < ee.w && e.h < ee.h
}

func (e *env) String() string {
	return strconv.Itoa(e.i)
}

type envs []*env

func (slice envs) Len() int {
	return len(slice)
}

func (slice envs) Less(i, j int) bool {
	return float64(slice[i].w) * float64(slice[i].h) < float64(slice[j].w) * float64(slice[j].h)
}

func (slice envs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	n, w, h := nextInt(), nextInt(), nextInt()
	card := &env{w, h, 0}
	all := make(envs, 0)
	all = append(all, card)
	for i := 0; i < n; i++ {
		ew, eh := nextInt(), nextInt()
		e := &env{ew, eh, i + 1}
		if card.ft(e) {
			all = append(all, e)
		}
	}
	sort.Sort(all)
	runtime.GC()
	d := make([]int, len(all))
	p := make([]int, len(all))
	m, ps := 0, 0
	for i := 0; i < len(d); i++ {
		d[i] = 1
		p[i] = -1
		for j := 0; j < i; j++ {
			if all[j].ft(all[i]) {
				if d[i] < d[j] + 1 {
					d[i] = d[j] + 1
					p[i] = j
				}
				if d[i] > m {
					m = d[i]
					ps = i
				}
			}
		}
	}
	path := make([]int, 0)
	for ps != -1 {
		path = append([]int{all[ps].i}, path...)
		ps = p[ps]
	}
	path = path[1:]
	printf("%d\n", len(path))
	if len(path) > 0 {
		s := fmt.Sprintf("%v", path)
		printf("%s\n", s[1:len(s)-1])
	}

}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

//  URL: http://codeforces.com/contest/4/problem/D
//  PROBLEM RESTATEMENT
//      Let A be a set of envelopes, each envelope contains integer height and width.
//      Chain C is a subset of A, where C[i] height and width > C[i-1] height
//      and width.
//      Find the chain of maximum size.
//  CONSTRAINTS
//      1 <= n <= 5000, 1 <= w, h <= 10^6
//  APPROACH
//      (1) Discard all envelopes that Peter's card cannot fit into.
//      (2) Sort and call the remaining envelopes set E.
//      (3) At any given step, we need to find the minimum envelope that has
//          height and width greater than the current element.
//      (4) In O(n^2), we can compute the maximum chain length using DP:
//            * Initialize each element of dp with 1.
//            * dp[i] = max(dp[i-1], dp[i-2] ... dp[0]) + 1

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type Envelope struct {
	Width  int
	Height int
	Child  int
	Number int
}

func solve(dp []int, e []Envelope) []int {
	// Solve the DP recurrence.
	for i := 1; i < len(dp); i++ {
		for j := 0; j < i; j++ {
			if e[i].Width > e[j].Width && e[i].Height > e[j].Height {
				if dp[j]+1 > dp[i] {
					dp[i] = dp[j] + 1
					e[i].Child = j
				}
			}
		}
	}
	// Find max element of DP - the length and final index of the chain.
	maxChainIndex := 0
	maxChainLength := 0
	for i := 0; i < len(dp); i++ {
		if dp[i] > maxChainLength {
			maxChainLength = dp[i]
			maxChainIndex = i
		}
	}
	if maxChainLength == 0 {
		return []int{}
	}
	// Follow the children to find the envelopes in the largest chain.
	var ans []int
	for maxChainIndex != -1 {
		ans = append(ans, e[maxChainIndex].Number)
		maxChainIndex = e[maxChainIndex].Child
	}
	return ans
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n, w, h int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &w, &h)
	var dp []int
	var e []Envelope
	for i := 0; i < n; i++ {
		var wi, hi int
		fmt.Fscanf(reader, "%d %d\n", &wi, &hi)
		if wi > w && hi > h {
			e = append(e, Envelope{wi, hi, -1, i + 1})
			dp = append(dp, 1)
		}
	}
	sort.Slice(e, func(i, j int) bool {
		return e[i].Width < e[j].Width
	})
	solution := solve(dp, e)
	l := len(solution)
	if l == 0 {
		fmt.Fprintf(writer, "%d\n", 0)
	} else {
		fmt.Fprintf(writer, "%d\n", l)
		for i := l - 1; i >= 0; i-- {
			fmt.Fprintf(writer, "%d ", solution[i])
		}
		fmt.Fprintf(writer, "\n")
	}
}

// problem_d
package main

import (
	"fmt"
	"sort"
)

type Letter struct {
	x   int
	y   int
	num int
	res int
	p   int
}

type ByLetter []Letter

func (a ByLetter) Len() int      { return len(a) }
func (a ByLetter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByLetter) Less(i, j int) bool {
	if a[i].x != a[j].x {
		return a[i].x < a[j].x
	}
	if a[i].y != a[j].y {
		return a[i].y < a[j].y
	}
	return a[i].num < a[j].num
}

func main() {
	var n, w, h int
	var lts ByLetter
	fmt.Scan(&n, &w, &h)
	//	fmt.Println(p1, p2, n)
	var w1, h1 int
	for i := 0; i < n; i++ {
		fmt.Scan(&w1, &h1)
		//		fmt.Println(w1, h1)
		if w1 > w && h1 > h {
			lts = append(lts, Letter{w1, h1, i, 1, -1})
		}
	}
	sort.Sort(lts)
	//	fmt.Println(lts)
	nn := lts.Len()
	if nn == 0 {
		fmt.Println("0")
		return
	}
	for i := 1; i < nn; i++ {
		for j := 0; j < i; j++ {
			if lts[j].x < lts[i].x && lts[j].y < lts[i].y &&
				lts[j].res >= lts[i].res {
				lts[i].res = lts[j].res + 1
				lts[i].p = j
			}
		}
	}
	max := 0
	mi := 0
	for i := 0; i < nn; i++ {
		if max < lts[i].res {
			max = lts[i].res
			mi = i
		}
	}
	//	fmt.Println(lts)
	fmt.Println(max)
	var ans []int
	for mi != -1 {
		ans = append(ans, lts[mi].num+1)
		mi = lts[mi].p
	}
	ans_len := len(ans)
	for i := ans_len - 1; i >= 0; i-- {
		fmt.Print(ans[i], " ")
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, w, h := readThreeNums(reader)
	envs := make([][]int, n)
	for i := 0; i < n; i++ {
		envs[i] = readNNums(reader, 2)
	}
	res := solve(n, w, h, envs)

	var buf bytes.Buffer

	buf.WriteString(fmt.Sprintf("%d\n", len(res)))

	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n, w, h int, envs [][]int) []int {
	items := make([]Envelope, n)
	var H int
	for i := 0; i < n; i++ {
		items[i] = Envelope{envs[i][0], envs[i][1], i}
		H = max(H, envs[i][1])
	}

	sort.Sort(Envelopes(items))
	H++
	arr := make([]int, 2*H)

	update := func(p int, v int) {
		p += H
		arr[p] = v
		for p > 0 {
			arr[p>>1] = max(arr[p], arr[p^1])
			p >>= 1
		}
	}

	get := func(l, r int) int {
		var res int
		l += H
		r += H

		for l < r {
			if l&1 == 1 {
				res = max(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = max(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	dp := make([]int, n+1)
	var best int
	for i := 0; i < n; i++ {
		cur := items[i]
		if cur.width <= w || cur.height <= h {
			continue
		}
		if i == 0 {
			dp[i] = 1
			update(cur.height, 1)
			continue
		}
		cnt := get(cur.height+1, H)
		dp[i] = cnt + 1
		update(cur.height, cnt+1)
		best = max(best, cnt+1)
	}

	if best == 0 {
		return nil
	}

	cur := -1
	for i := n - 1; i >= 0; i-- {
		if dp[i] == best {
			cur = i
			break
		}
	}
	res := make([]int, 0, best)
	res = append(res, items[cur].index+1)

	for i := cur - 1; i >= 0; i-- {
		if dp[i]+1 == best && items[i].width > items[cur].width && items[i].height > items[cur].height {
			best--
			cur = i
			res = append(res, items[cur].index+1)
		}
	}
	//reverse(res)

	return res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Envelope struct {
	width  int
	height int
	index  int
}

type Envelopes []Envelope

func (ps Envelopes) Len() int {
	return len(ps)
}

func (ps Envelopes) Less(i, j int) bool {
	return ps[i].width > ps[j].width || ps[i].width == ps[j].width && ps[i].height > ps[j].height
}

func (ps Envelopes) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, w, h := readThreeNums(reader)
	envs := make([][]int, n)
	for i := 0; i < n; i++ {
		envs[i] = readNNums(reader, 2)
	}
	res := solve(n, w, h, envs)

	var buf bytes.Buffer

	buf.WriteString(fmt.Sprintf("%d\n", len(res)))

	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n, h, w int, envs [][]int) []int {
	items := make([]Envelope, n)
	var H int
	for i := 0; i < n; i++ {
		items[i] = Envelope{envs[i][0], envs[i][1], i}
		H = max(H, envs[i][1])
	}

	sort.Sort(Envelopes(items))
	H++
	arr := make([]int, 2*H)

	update := func(p int, v int) {
		p += H
		arr[p] = v
		for p > 0 {
			arr[p>>1] = max(arr[p], arr[p^1])
			p >>= 1
		}
	}

	get := func(l, r int) int {
		var res int
		l += H
		r += H

		for l < r {
			if l&1 == 1 {
				res = max(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = max(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	dp := make([]int, n+1)
	var best int
	for i := 0; i < n; i++ {
		cur := items[i]
		if cur.width <= w || cur.height <= h {
			break
		}
		if i == 0 {
			dp[i] = 1
			update(cur.height, 1)
			continue
		}
		cnt := get(cur.height+1, H)
		dp[i] = cnt + 1
		update(cur.height, cnt+1)
		best = max(best, cnt+1)
	}

	if best == 0 {
		return nil
	}

	cur := -1
	for i := n - 1; i >= 0; i-- {
		if dp[i] == best {
			cur = i
			break
		}
	}
	res := make([]int, 0, best)
	res = append(res, items[cur].index+1)

	for i := cur - 1; i >= 0; i-- {
		if dp[i]+1 == best && items[i].width > items[cur].width && items[i].height > items[cur].height {
			best--
			cur = i
			res = append(res, items[cur].index+1)
		}
	}
	//reverse(res)

	return res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Envelope struct {
	width  int
	height int
	index  int
}

type Envelopes []Envelope

func (ps Envelopes) Len() int {
	return len(ps)
}

func (ps Envelopes) Less(i, j int) bool {
	return ps[i].width > ps[j].width || ps[i].width == ps[j].width && ps[i].height > ps[j].height
}

func (ps Envelopes) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type envelope struct {
	w, h, index, len int
}

func solve() {
	n := readInt()
	w := readInt()
	h := readInt()

	e := make([]envelope, 0, n)
	for i := 0; i < n; i++ {
		ew := readInt()
		eh := readInt()
		if ew <= w || eh <= h {
			// card won't fit, ignore it
			continue
		}
		e = append(e, envelope{ew, eh, i + 1, 0})
	}

	if len(e) == 0 {
		fmt.Println(0)
		return
	}

	// Sort by area
	sort.Slice(e, func(i, j int) bool {
		ai := uint64(e[i].w) * uint64(e[i].h)
		aj := uint64(e[j].w) * uint64(e[j].h)
		return ai < aj
	})

	maxlen := 0
	for inner, v_inner := range e {
		for outer := inner; outer < len(e); outer++ {
			if v_inner.w >= e[outer].w || v_inner.h >= e[outer].h {
				// doesn't fit: too wide or too tall
				continue
			}
			e[outer].len = max(v_inner.len+1, e[outer].len)
			maxlen = max(e[outer].len, maxlen)
		}
	}
	fmt.Println(maxlen + 1)

	a := make([]int, maxlen+1)
	lastidx := len(e)
	for i := len(e) - 1; i >= 0; i-- {
		if e[i].len == maxlen {
			if lastidx == len(e) || (e[i].h < e[lastidx].h &&
				e[i].w < e[lastidx].h) {
				a[maxlen] = e[i].index
				maxlen--
				lastidx = i
			}
		}
	}

	space := ""
	for _, i := range a {
		fmt.Printf("%v%v", space, i)
		space = " "
	}
	fmt.Println()

}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type envelope struct {
	w, h, index, len int
}

func solve() {
	n := readInt()
	w := readInt()
	h := readInt()

	e := make([]envelope, 0, n)
	for i := 0; i < n; i++ {
		ew := readInt()
		eh := readInt()
		if ew <= w || eh <= h {
			// card won't fit, ignore it
			continue
		}
		e = append(e, envelope{ew, eh, i + 1, 0})
	}

	if len(e) == 0 {
		fmt.Println(0)
		return
	}

	// Sort by area
	sort.Slice(e, func(i, j int) bool {
		return (e[i].w * e[i].h) < (e[j].w * e[j].h)
	})

	maxlen := 0
	for inner, v_inner := range e {
		for outer := inner; outer < len(e); outer++ {
			if v_inner.w >= e[outer].w || v_inner.h >= e[outer].h {
				// doesn't fit: too wide or too tall
				continue
			}
			e[outer].len = max(v_inner.len+1, e[outer].len)
			maxlen = max(e[outer].len, maxlen)
		}
	}
	fmt.Println(maxlen + 1)

	a := make([]int, maxlen+1)
	for i := len(e) - 1; i >= 0; i-- {
		if e[i].len == maxlen {
			a[maxlen] = e[i].index
			maxlen--
		}
	}

	space := ""
	for _, i := range a {
		fmt.Printf("%v%v", space, i)
		space = " "
	}
	fmt.Println()

}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type envelope struct {
	w, h, index, len int
}

func solve() {
	n := readInt()
	w := readInt()
	h := readInt()

	e := make([]envelope, 0, n)
	for i := 0; i < n; i++ {
		ew := readInt()
		eh := readInt()
		if ew <= w || eh <= h {
			// card won't fit, ignore it
			continue
		}
		e = append(e, envelope{ew, eh, i + 1, 0})
	}

	if len(e) == 0 {
		fmt.Println(0)
		return
	}

	// Sort by area
	sort.Slice(e, func(i, j int) bool {
		ai := uint64(e[i].w) * uint64(e[i].h)
		aj := uint64(e[j].w) * uint64(e[j].h)
		return ai < aj
	})

	maxlen := 0
	for inner, v_inner := range e {
		for outer := inner; outer < len(e); outer++ {
			if v_inner.w >= e[outer].w || v_inner.h >= e[outer].h {
				// doesn't fit: too wide or too tall
				continue
			}
			e[outer].len = max(v_inner.len+1, e[outer].len)
			maxlen = max(e[outer].len, maxlen)
		}
	}
	fmt.Println(maxlen + 1)

	a := make([]int, maxlen+1)
	for i := len(e) - 1; i >= 0; i-- {
		if e[i].len == maxlen {
			a[maxlen] = e[i].index
			maxlen--
		}
	}

	space := ""
	for _, i := range a {
		fmt.Printf("%v%v", space, i)
		space = " "
	}
	fmt.Println()

}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var in = bufio.NewScanner(os.Stdin)

var n, w, h, max, maxi int
var e [5001][3]int
var dep [5001]int
var prev [5001]int
var ret [5001]int

type Matrix [5001][3]int

func init() {
  in.Split(bufio.ScanWords)
  for i := range dep {
    dep[i] = 1
  }

  for i := range prev {
    prev[i] = -1
  }
}

func (m Matrix) Len() int           { return n }
func (m Matrix) Less(i, j int) bool { return m[i][0] < m[j][0] }
func (m *Matrix) Swap(i, j int)     { m[i], m[j] = m[j], m[i] }

func main() {
  n, w, h = readInt(), readInt(), readInt()

  for i := 0; i < n; i++ {
    tw, th := readInt(), readInt()
    if tw > w && th > h {
      e[i][0], e[i][1], e[i][2] = tw, th, i
    }
  }

  if e[0][0] == 0 {
    fmt.Println("0")
    return
  }

  m := Matrix(e)
  sort.Sort(&m)

  for i := 1; i < n; i++ {
    for j := 0; j < i; j++ {
      if m[i][0] > m[j][0] && m[i][1] > m[j][1] && dep[i] < dep[j]+1 {
        dep[i] = dep[j] + 1
        prev[i] = j
      }
    }
  }

  for i := 0; i < n; i++ {
    if max < dep[i] {
      max = dep[i]
      maxi = i
    }
  }

  i := maxi
  j := 0
  for {
    ret[j] = m[i][2]
    i = prev[i]
    if i == -1 {
      break
    }
    j++
  }

  fmt.Printf("%d\n", max)
  for i := j; i >= 0; i-- {
    fmt.Printf("%d ", ret[i])
  }
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var in = bufio.NewScanner(os.Stdin)

var n, w, h, max, maxi, elen int
var e [5001][3]int
var dep [5001]int
var prev [5001]int
var ret [5001]int

type Matrix [5001][3]int

func init() {
  in.Split(bufio.ScanWords)
  for i := range dep {
    dep[i] = 1
  }

  for i := range prev {
    prev[i] = -1
  }
}

func (m Matrix) Len() int           { return elen }
func (m Matrix) Less(i, j int) bool { return m[i][0] < m[j][0] }
func (m *Matrix) Swap(i, j int)     { m[i], m[j] = m[j], m[i] }

func main() {
  n, w, h = readInt(), readInt(), readInt()

  for i := 0; i < n; i++ {
    tw, th := readInt(), readInt()
    if tw > w && th > h {
      e[i][0], e[i][1], e[i][2] = tw, th, i
      elen++
    }
  }

  if elen == 0 {
    fmt.Println("0")
    return
  }

  m := Matrix(e)
  sort.Sort(&m)

  for i := 1; i < elen; i++ {
    for j := 0; j < i; j++ {
      if m[i][0] > m[j][0] && m[i][1] > m[j][1] && dep[i] < dep[j]+1 {
        dep[i] = dep[j] + 1
        prev[i] = j
      }
    }
  }

  for i := 0; i < elen; i++ {
    if max < dep[i] {
      max = dep[i]
      maxi = i
    }
  }

  i := maxi
  j := 0
  for {
    ret[j] = m[i][2]
    i = prev[i]
    if i == -1 {
      break
    }
    j++
  }

  fmt.Printf("%d\n", max)
  for i := j; i >= 0; i-- {
    fmt.Printf("%d ", ret[i]+1)
  }
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var in = bufio.NewScanner(os.Stdin)
var n, w, h int

func init() {
  in.Split(bufio.ScanWords)
}

type Matrix [][]int

func (m Matrix) Len() int { return n }
func (m Matrix) Less(i, j int) bool {
  return m[i][0] < m[j][0]
}

func (m Matrix) Swap(i, j int) { m[i], m[j] = m[j], m[i] }

func main() {
  maxSum, maxIdx := -1, -1
  n, w, h = readInt(), readInt(), readInt()
  dp := make([][]int, n)
  for i := range dp {
    dp[i] = make([]int, n)
  }

  e := make([][]int, n)
  for i := range e {
    e[i] = make([]int, 3)
  }

  for i := 0; i < n; i++ {
    e[i][0], e[i][1], e[i][2] = readInt(), readInt(), i
  }

  m := Matrix(e)
  sort.Sort(&m)

  for i := 0; i < n; i++ {
    if m[i][0] > w && m[i][1] > h {
      for j := i + 1; j < n; j++ {
        if m[j][0] > m[i][0] && m[j][1] > m[i][1] {
          dp[i][j] = 1
        }
      }
    }
  }

  for i := 0; i < n; i++ {
    sum := 0
    for j := 0; j < n; j++ {
      if dp[j][i] == 1 {
        sum++
      }
    }

    if maxSum < sum {
      maxSum = sum
      maxIdx = i
    }
  }

  fmt.Printf("%d\n", maxSum+1)
  for i := 0; i < n; i++ {
    if dp[i][maxIdx] == 1 {
      fmt.Printf("%d ", m[i][2]+1)
    }
  }
  fmt.Printf("%d\n", m[maxIdx][2]+1)
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var in = bufio.NewScanner(os.Stdin)
var n, w, h int

func init() {
  in.Split(bufio.ScanWords)
}

type Matrix [][]int

func (m Matrix) Len() int { return n }
func (m Matrix) Less(i, j int) bool {
  return m[i][0] < m[j][0]
}

func (m Matrix) Swap(i, j int) { m[i], m[j] = m[j], m[i] }

func main() {
  maxSum, maxIdx := -1, -1
  n, w, h = readInt(), readInt(), readInt()
  dp := make([][]int, n)
  for i := range dp {
    dp[i] = make([]int, n)
  }

  e := make([][]int, n)
  for i := range e {
    e[i] = make([]int, 3)
  }

  for i := 0; i < n; i++ {
    e[i][0], e[i][1], e[i][2] = readInt(), readInt(), i
  }

  m := Matrix(e)
  sort.Sort(&m)

  for i := 0; i < n; i++ {
    if m[i][0] > w && m[i][1] > h {
      dp[i][i] = 1
      for j := i + 1; j < n; j++ {
        if m[j][0] > m[i][0] && m[j][1] > m[i][1] {
          dp[i][j] = 1
        }
      }
    }
  }

  for i := 0; i < n; i++ {
    sum := 0
    for j := 0; j < n; j++ {
      if dp[j][i] == 1 {
        sum++
      }
    }

    if maxSum < sum {
      maxSum = sum
      maxIdx = i
    }
  }

  fmt.Printf("%d\n", maxSum)
  for i := 0; i < n; i++ {
    if dp[i][maxIdx] == 1 {
      fmt.Printf("%d ", m[i][2]+1)
    }
  }
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var in = bufio.NewScanner(os.Stdin)

var n, w, h, max, maxi, elen int
var e [5001][3]int
var dep [5001]int
var prev [5001]int
var ret [5001]int

type Matrix [5001][3]int

func init() {
  in.Split(bufio.ScanWords)
  for i := range dep {
    dep[i] = 1
  }

  for i := range prev {
    prev[i] = -1
  }
}

func (m Matrix) Len() int           { return elen }
func (m Matrix) Less(i, j int) bool { return m[i][0] < m[j][0] }
func (m *Matrix) Swap(i, j int)     { m[i], m[j] = m[j], m[i] }

func main() {
  n, w, h = readInt(), readInt(), readInt()

  for i := 0; i < n; i++ {
    tw, th := readInt(), readInt()
    if tw > w && th > h {
      e[elen][0], e[elen][1], e[elen][2] = tw, th, i
      elen++
    }
  }

  if elen == 0 {
    fmt.Println("0")
    return
  }

  m := Matrix(e)
  sort.Sort(&m)

  for i := 1; i < elen; i++ {
    for j := 0; j < i; j++ {
      if m[i][0] > m[j][0] && m[i][1] > m[j][1] && dep[i] < dep[j]+1 {
        dep[i] = dep[j] + 1
        prev[i] = j
      }
    }
  }

  for i := 0; i < elen; i++ {
    if max < dep[i] {
      max = dep[i]
      maxi = i
    }
  }

  i := maxi
  j := 0
  for {
    fmt.Println(m[i][0])
    ret[j] = m[i][2]
    i = prev[i]
    if i == -1 {
      break
    }
    j++
  }

  fmt.Printf("%d\n", max)
  for i := j; i >= 0; i-- {
    fmt.Printf("%d ", ret[i]+1)
  }
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var in = bufio.NewScanner(os.Stdin)

var n, w, h, max, maxi, elen int
var e [5001][3]int
var dep [5001]int
var prev [5001]int
var ret [5001]int

type Matrix [5001][3]int

func init() {
  in.Split(bufio.ScanWords)
  for i := range dep {
    dep[i] = 1
  }

  for i := range prev {
    prev[i] = -1
  }
}

func (m Matrix) Len() int           { return elen }
func (m Matrix) Less(i, j int) bool { return m[i][0] < m[j][0] }
func (m *Matrix) Swap(i, j int)     { m[i], m[j] = m[j], m[i] }

func main() {
  n, w, h = readInt(), readInt(), readInt()

  for i := 0; i < n; i++ {
    tw, th := readInt(), readInt()
    if tw > w && th > h {
      e[i][0], e[i][1], e[i][2] = tw, th, i
      elen++
    }
  }

  if elen == 0 {
    fmt.Println("0")
    return
  }

  m := Matrix(e)
  sort.Sort(&m)

  for i := 1; i < elen; i++ {
    for j := 0; j < i; j++ {
      if m[i][0] > m[j][0] && m[i][1] > m[j][1] && dep[i] < dep[j]+1 {
        dep[i] = dep[j] + 1
        prev[i] = j
      }
    }
  }

  for i := 0; i < elen; i++ {
    if max < dep[i] {
      max = dep[i]
      maxi = i
    }
  }

  i := maxi
  j := 0
  for {
    ret[j] = m[i][2]
    i = prev[i]
    if i == -1 {
      break
    }
    j++
  }

  fmt.Printf("%d\n", max)
  for i := j; i >= 0; i-- {
    fmt.Printf("%d ", ret[i])
  }
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var in = bufio.NewScanner(os.Stdin)

var n, w, h, max, maxi int
var e [5001][3]int
var dep [5001]int
var prev [5001]int
var ret [5001]int

type Matrix [5001][3]int

func init() {
  in.Split(bufio.ScanWords)
  for i := range dep {
    dep[i] = 1
  }

  for i := range prev {
    prev[i] = -1
  }
}

func (m Matrix) Len() int           { return n }
func (m Matrix) Less(i, j int) bool { return m[i][0] < m[j][0] }
func (m *Matrix) Swap(i, j int)     { m[i], m[j] = m[j], m[i] }

func main() {
  n, w, h = readInt(), readInt(), readInt()

  for i := 0; i < n; i++ {
    tw, th := readInt(), readInt()
    if tw > w && th > h {
      e[i][0], e[i][1], e[i][2] = tw, th, i
    }
  }

  if e[0][0] == 0 {
    fmt.Println("0")
    return
  }

  m := Matrix(e)
  sort.Sort(&m)

  for i := 1; i < n; i++ {
    for j := 0; j < i; j++ {
      if m[i][0] > m[j][0] && m[i][1] > m[j][1] && dep[i] < dep[j]+1 {
        dep[i] = dep[j] + 1
        prev[i] = j
      }
    }
  }

  for i := 0; i < n; i++ {
    if max < dep[i] {
      max = dep[i]
      maxi = i
    }
  }

  i := maxi
  j := 0
  for {
    ret[j] = m[i][2]
    i = prev[i]
    if i == -1 {
      break
    }
    j++
  }

  fmt.Printf("%d\n", max)
  for i := j; i >= 0; i-- {
    fmt.Printf("%d ", ret[i]+1)
  }
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	//if n == 6 && w == 1 && h == 1 {
	//	debug = true
	//}

	type envelope struct {
		w, h int
	}

	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		return int64(envs[i].w)*int64(envs[i].h) < int64(envs[j].w)*int64(envs[j].h) && envs[i].w <= envs[j].w && envs[i].h <= envs[j].h
	})

	if debug {
		printf("%v\n", envs)
	}
	idxList := make([]int, 0, len(envs))

	lastEnv := 0
	for i := 0; i < len(envs); i++ {
		if i > 0 && (envs[i].w <= envs[lastEnv].w || envs[i].h <= envs[lastEnv].h) {
			continue
		}
		idxList = append(idxList, envIdxMap[envs[i]]+1)
		lastEnv = i
	}

	printf("%d\n", len(idxList))
	for i := 0; i < len(idxList); i++ {
		printf("%d ", idxList[i])
		if i == len(idxList)-1 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	if n == 6 && w == 1 && h == 1 {
		debug = true
	}

	type envelope struct {
		w, h int
	}

	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		//return envs[i].w < envs[j].w && envs[i].h < envs[j].h
		return envs[i].w*envs[i].h < envs[j].w*envs[j].h
	})
	if debug {
		printf("%v\n", envs)
	}
	idxList := make([]int, 0, len(envs))

	lastEnv := 0
	for i := 0; i < len(envs); i++ {
		if i > 0 && (envs[i].w <= envs[lastEnv].w || envs[i].h <= envs[lastEnv].h) {
			continue
		}
		idxList = append(idxList, envIdxMap[envs[i]]+1)
		lastEnv = i
	}

	printf("%d\n", len(idxList))
	for i := 0; i < len(idxList); i++ {
		printf("%d ", idxList[i])
		if i == len(idxList)-1 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	if n == 6 && w == 1 && h == 1 {
		debug = true
	}

	type envelope struct {
		w, h int
	}

	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	if debug {
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		//return envs[i].w < envs[j].w && envs[i].h < envs[j].h
		return envs[i].w*envs[i].h < envs[j].w*envs[j].h
	})
	if debug {
		printf("%v\n", envs)
	}
	idxList := make([]int, 0, len(envs))

	lastEnv := 0
	for i := 0; i < len(envs); i++ {
		if i > 0 && (envs[i].w <= envs[lastEnv].w || envs[i].h <= envs[lastEnv].h) {
			continue
		}
		idxList = append(idxList, envIdxMap[envs[i]]+1)
		lastEnv = i
	}

	printf("%d\n", len(idxList))
	for i := 0; i < len(idxList); i++ {
		printf("%d ", idxList[i])
		if i == len(idxList)-1 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	type envelope struct {
		w, h int
	}

	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	//printf("%v\n", envs)
	sort.Slice(envs, func(i, j int) bool {
		//return envs[i].w < envs[j].w && envs[i].h < envs[j].h
		return envs[i].w*envs[i].h < envs[j].w*envs[j].h
	})
	//printf("%v\n", envs)
	idxList := make([]int, 0, len(envs))

	lastIdx := 0
	for i := 0; i < len(envs); i++ {
		if i > 0 && (envs[i].w <= envs[lastIdx].w || envs[i].h <= envs[lastIdx].h) {
			continue
		}
		idxList = append(idxList, envIdxMap[envs[i]]+1)
		lastIdx = i
	}

	printf("%d\n", len(idxList))
	for i := 0; i < len(idxList); i++ {
		printf("%d ", idxList[i])
		if i == len(idxList)-1 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	type envelope struct {
		w, h int
	}

	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	sort.Slice(envs, func(i, j int) bool {
		return envs[i].w < envs[j].w && envs[i].h < envs[j].h
	})

	idxList := make([]int, 0, len(envs))

	for i := 0; i < len(envs); i++ {
		if i > 0 && (envs[i].w <= envs[i-1].w || envs[i].h <= envs[i-1].h) {
			continue
		}
		idxList = append(idxList, envIdxMap[envs[i]]+1)
	}

	printf("%d\n", len(idxList))
	for i := 0; i < len(idxList); i++ {
		printf("%d ", idxList[i])
		if i == len(idxList)-1 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	//if n == 6 && w == 1 && h == 1 {
	//	debug = true
	//}

	type envelope struct {
		w, h int
	}

	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		//return envs[i].w < envs[j].w && envs[i].h < envs[j].h
		return int64(envs[i].w)*int64(envs[i].h) < int64(envs[j].w)*int64(envs[j].h)
	})
	if debug {
		printf("%v\n", envs)
	}
	idxList := make([]int, 0, len(envs))

	lastEnv := 0
	for i := 0; i < len(envs); i++ {
		if i > 0 && (envs[i].w <= envs[lastEnv].w || envs[i].h <= envs[lastEnv].h) {
			continue
		}
		idxList = append(idxList, envIdxMap[envs[i]]+1)
		lastEnv = i
	}

	printf("%d\n", len(idxList))
	for i := 0; i < len(idxList); i++ {
		printf("%d ", idxList[i])
		if i == len(idxList)-1 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

type envelope struct {
	w, h int
}

func readEnvs(n, w, h int) ([]envelope, map[envelope]int) {
	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	return envs, envIdxMap
}

func findlis(envs []envelope) []int {
	lis := make([]int, len(envs))
	parent := make([]int, len(envs))

	globalMaxLisIdx := 0

	for i := 0; i < len(envs); i++ {
		maxLis := lis[i]
		maxLisIdx := -1
		for j := 0; j < i; j++ {
			if envs[i].w > envs[j].w && envs[i].h > envs[j].h && lis[j] > maxLis {
				maxLis = lis[j]
				maxLisIdx = j
			}
		}

		lis[i] = maxLis + 1
		parent[i] = maxLisIdx

		if lis[globalMaxLisIdx] < lis[i] {
			globalMaxLisIdx = i
		}
	}

	idxList := make([]int, 0)
	for idx := globalMaxLisIdx; idx != -1; {
		idxList = append(idxList, idx)
		idx = parent[idx]
	}

	return idxList
}

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	envs, envIdxMap := readEnvs(n, w, h)

	if len(envs) == 0 {
		printf("0\n")
		return
	}

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		return envs[i].w <= envs[j].w && envs[i].h <= envs[j].h
	})

	if debug {
		printf("%v\n", envs)
	}

	idxList := findlis(envs)

	printf("%d\n", len(idxList))
	for i := len(idxList) - 1; i >= 0; i-- {
		if debug {
			printf("%d (%v) ", envIdxMap[envs[idxList[i]]]+1, envs[idxList[i]])
		} else {
			printf("%d ", envIdxMap[envs[idxList[i]]]+1)
		}
		if i == 0 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

type envelope struct {
	w, h int
}

func readEnvs(n, w, h int) ([]envelope, map[envelope]int) {
	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	return envs, envIdxMap
}

func findlis(envs []envelope) []int {
	lis := make([]int, len(envs))
	parent := make([]int, len(envs))

	globalMaxLisIdx := 0

	for i := 0; i < len(envs); i++ {
		maxLis := lis[i]
		maxLisIdx := -1
		for j := 0; j < i; j++ {
			if envs[i].w > envs[j].w && envs[i].h > envs[j].h && lis[j] >= maxLis {
				maxLis = lis[j]
				maxLisIdx = j
			}
		}

		lis[i] = maxLis + 1
		parent[i] = maxLisIdx

		if lis[globalMaxLisIdx] <= lis[i] {
			globalMaxLisIdx = i
		}
	}

	idxList := make([]int, 0)
	for idx := globalMaxLisIdx; idx != -1; {
		idxList = append(idxList, idx)
		idx = parent[idx]
	}

	return idxList
}

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	envs, envIdxMap := readEnvs(n, w, h)

	if len(envs) == 0 {
		printf("0\n")
		return
	}

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		return int64(envs[i].w)*int64(envs[i].h) < int64(envs[j].w)*int64(envs[j].h) && envs[i].w <= envs[j].w && envs[i].h <= envs[j].h
	})

	if debug {
		printf("%v\n", envs)
	}

	idxList := findlis(envs)

	printf("%d\n", len(idxList))
	for i := len(idxList) - 1; i >= 0; i-- {
		if debug {
			printf("%d (%v) ", envIdxMap[envs[idxList[i]]]+1, envs[idxList[i]])
		} else {
			printf("%d ", envIdxMap[envs[idxList[i]]]+1)
		}
		if i == 0 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

type envelope struct {
	w, h int
}

func readEnvs(n, w, h int) ([]envelope, map[envelope]int) {
	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	return envs, envIdxMap
}

func findlis(envs []envelope) []int {
	lis := make([]int, len(envs))
	parent := make([]int, len(envs))

	globalMaxLisIdx := 0

	for i := 0; i < len(envs); i++ {
		maxLis := lis[i]
		maxLisIdx := -1
		for j := 0; j < i; j++ {
			if envs[i].w > envs[j].w && envs[i].h > envs[j].h && lis[j] > maxLis {
				maxLis = lis[j]
				maxLisIdx = j
			}
		}

		lis[i] = maxLis + 1
		parent[i] = maxLisIdx

		if lis[globalMaxLisIdx] < lis[i] {
			globalMaxLisIdx = i
		}
	}

	idxList := make([]int, 0)
	for idx := globalMaxLisIdx; idx != -1; {
		idxList = append(idxList, idx)
		idx = parent[idx]
	}

	return idxList
}

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	envs, envIdxMap := readEnvs(n, w, h)

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		return envs[i].w <= envs[j].w && envs[i].h <= envs[j].h
	})

	if debug {
		printf("%v\n", envs)
	}

	idxList := findlis(envs)

	for i := len(idxList) - 1; i >= 0; i-- {
		if debug {
			printf("%d (%v) ", envIdxMap[envs[idxList[i]]]+1, envs[idxList[i]])
		} else {
			printf("%d ", envIdxMap[envs[idxList[i]]]+1)
		}
		if i == 0 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	//if n == 6 && w == 1 && h == 1 {
	//	debug = true
	//}

	type envelope struct {
		w, h int
	}

	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		return int64(envs[i].w)*int64(envs[i].h) < int64(envs[j].w)*int64(envs[j].h) && envs[i].w < envs[j].w && envs[i].h < envs[j].h
	})

	if debug {
		printf("%v\n", envs)
	}
	idxList := make([]int, 0, len(envs))

	lastEnv := 0
	for i := 0; i < len(envs); i++ {
		if i > 0 && (envs[i].w <= envs[lastEnv].w || envs[i].h <= envs[lastEnv].h) {
			continue
		}
		idxList = append(idxList, envIdxMap[envs[i]]+1)
		lastEnv = i
	}

	printf("%d\n", len(idxList))
	for i := 0; i < len(idxList); i++ {
		printf("%d ", idxList[i])
		if i == len(idxList)-1 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

type envelope struct {
	w, h int
}

func readEnvs(n, w, h int) ([]envelope, map[envelope]int) {
	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	return envs, envIdxMap
}

func findlis(envs []envelope) []int {
	lis := make([]int, len(envs))
	parent := make([]int, len(envs))

	globalMaxLisIdx := 0

	for i := 0; i < len(envs); i++ {
		maxLis := lis[i]
		maxLisIdx := -1
		for j := 0; j < i; j++ {
			if envs[i].w > envs[j].w && envs[i].h > envs[j].h && lis[j] > maxLis {
				maxLis = lis[j]
				maxLisIdx = j
			}
		}

		lis[i] = maxLis + 1
		parent[i] = maxLisIdx

		if lis[globalMaxLisIdx] < lis[i] {
			globalMaxLisIdx = i
		}
	}

	idxList := make([]int, 0)
	for idx := globalMaxLisIdx; idx != -1; {
		idxList = append(idxList, idx)
		idx = parent[idx]
	}

	return idxList
}

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	envs, envIdxMap := readEnvs(n, w, h)

	if len(envs) == 0 {
		printf("0\n")
		return
	}

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		return envs[i].w < envs[j].w && envs[i].h < envs[j].h
	})

	if debug {
		printf("%v\n", envs)
	}

	idxList := findlis(envs)

	printf("%d\n", len(idxList))
	for i := len(idxList) - 1; i >= 0; i-- {
		if debug {
			printf("%d (%v) ", envIdxMap[envs[idxList[i]]]+1, envs[idxList[i]])
		} else {
			printf("%d ", envIdxMap[envs[idxList[i]]]+1)
		}
		if i == 0 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	type envelope struct {
		w, h int
	}

	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	//printf("%v\n", envs)
	sort.Slice(envs, func(i, j int) bool {
		//return envs[i].w < envs[j].w && envs[i].h < envs[j].h
		return envs[i].w*envs[i].h < envs[j].w*envs[j].h
	})
	//printf("%v\n", envs)
	idxList := make([]int, 0, len(envs))

	lastEnv := 0
	for i := 0; i < len(envs); i++ {
		if i > 0 && (envs[i].w <= envs[lastEnv].w || envs[i].h <= envs[lastEnv].h) {
			continue
		}
		idxList = append(idxList, envIdxMap[envs[i]]+1)
		lastEnv = i
	}

	printf("%d\n", len(idxList))
	for i := 0; i < len(idxList); i++ {
		printf("%d ", idxList[i])
		if i == len(idxList)-1 {
			printf("\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	_, err := fmt.Fprintf(writer, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func scanf(f string, a ...interface{}) {
	_, err := fmt.Fscanf(reader, f, a...)
	if err != nil {
		log.Fatal(err)
	}
}

func readline() string {
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	name = strings.TrimRight(name, "\r\n")

	return name
}

func flush() {
	err := writer.Flush()
	if err != nil {
		log.Fatal(err)
	}
}

var debug = false

type envelope struct {
	w, h int
}

func readEnvs(n, w, h int) ([]envelope, map[envelope]int) {
	envs := make([]envelope, 0, n)
	envIdxMap := make(map[envelope]int)

	for i := 0; i < n; i++ {
		var ew, eh int
		scanf("%d %d\n", &ew, &eh)
		if ew <= w || eh <= h {
			continue
		}

		env := envelope{ew, eh}

		if _, ok := envIdxMap[env]; !ok {
			envIdxMap[env] = i
			envs = append(envs, env)
		}
	}

	return envs, envIdxMap
}

func findlis(envs []envelope) []int {
	lis := make([]int, len(envs))
	parent := make([]int, len(envs))

	globalMaxLisIdx := 0

	for i := 0; i < len(envs); i++ {
		maxLis := lis[i]
		maxLisIdx := -1
		for j := 0; j < i; j++ {
			if envs[i].w > envs[j].w && envs[i].h > envs[j].h && lis[j] > maxLis {
				maxLis = lis[j]
				maxLisIdx = j
			}
		}

		lis[i] = maxLis + 1
		parent[i] = maxLisIdx

		if lis[globalMaxLisIdx] < lis[i] {
			globalMaxLisIdx = i
		}
	}

	idxList := make([]int, 0)
	for idx := globalMaxLisIdx; idx != -1; {
		idxList = append(idxList, idx)
		idx = parent[idx]
	}

	return idxList
}

func main() {
	defer flush()
	var n, w, h int
	scanf("%d %d %d\n", &n, &w, &h)

	envs, envIdxMap := readEnvs(n, w, h)

	if len(envs) == 0 {
		printf("0\n")
		return
	}

	if debug {
		printf("bits: %d\n", (32 << (^uint(0) >> 63)))
		printf("%v\n", envIdxMap)
		printf("%v\n", envs)
	}

	sort.Slice(envs, func(i, j int) bool {
		return int64(envs[i].w)*int64(envs[i].h) < int64(envs[j].w)*int64(envs[j].h) && envs[i].w < envs[j].w && envs[i].h < envs[j].h
	})

	if debug {
		printf("%v\n", envs)
	}

	idxList := findlis(envs)

	printf("%d\n", len(idxList))
	for i := len(idxList) - 1; i >= 0; i-- {
		if debug {
			printf("%d (%v) ", envIdxMap[envs[idxList[i]]]+1, envs[idxList[i]])
		} else {
			printf("%d ", envIdxMap[envs[idxList[i]]]+1)
		}
		if i == 0 {
			printf("\n")
		}
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"sort"
)

type envelope struct {
	w, h, i int
}

type input struct {
	n int
	w, h int
	es []envelope
}

type output struct {
	ary []int
	memo []int
	crumbs []int
	max_len, max_idx int
}

func read_input() *input {
	result := &input{}
	r := bufio.NewReader(os.Stdin)

	fmt.Fscanf(r, "%d %d %d\n", &result.n, &result.w, &result.h)

	result.es = make([]envelope, result.n)

	for i := 0; i < result.n; i++ {
		result.es[i].i = i + 1
		fmt.Fscanf(r, "%d %d\n", &result.es[i].w, &result.es[i].h)
	}

	return result
}

func process_input(inp *input) *output {
	sort.Sort(ByArea(inp.es))

	out := &output{}
	out.max_len, out.max_idx = 0, -1
 	out.memo = make([]int, inp.n)

	// initialize the memo, taking into account that valid envelopes must be > postcard's dimensions
	for i := range out.memo {
		if inp.es[i].w > inp.w && inp.es[i].h > inp.h {
			out.memo[i] = 1
			if out.max_len == 0 {
				out.max_len = 1
				out.max_idx = i
			}
		}
 	}

	out.crumbs = make([]int, inp.n)
	for i := range out.crumbs {
		out.crumbs[i] = -1
	}

 	for i := 0; i < inp.n; i++ {
 		for j := 0; j < inp.n; j++ {
			if i == j {
				// we are not interested in link to ourselves
				continue
			}

			// ignore too small an envelope
			if inp.es[i].w <= inp.w || inp.es[i].h <= inp.h {
				continue
			}

			if inp.es[i].w < inp.es[j].w && inp.es[i].h < inp.es[j].h {
				// i -> j
				if out.memo[j] < out.memo[i] + 1 {
					out.memo[j] = out.memo[i] + 1
					out.crumbs[j] = i

					if out.memo[j] > out.max_len {
						out.max_len = out.memo[j]
						out.max_idx = j
					}
				}
			}
		}
	}

	out.ary = make([]int, out.max_len)
	for i, idx := out.max_len - 1, out.max_idx; i >= 0; i-- {
		out.ary[i] = inp.es[idx].i
		idx        = out.crumbs[idx]
	}

	return out
}

// ByArea implements sort.Interface for []envelope based on the area of the envelope.
type ByArea []envelope

func (a ByArea) Len() int           { return len(a) }
func (a ByArea) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByArea) Less(i, j int) bool { return a[i].w * a[i].h < a[j].w * a[j].h }

func main() {
	i := read_input()

	out := process_input(i)
	fmt.Printf("%d\n", out.max_len)
	if (out.max_len != 0) {
		fmt.Printf("%d\n", out.max_len)
		idx, l := 0, len(out.ary)
		fmt.Printf("%d", out.ary[idx])
		for idx = 1; idx < l; idx++ {
			fmt.Printf(" %d", out.ary[idx])
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"sort"
)

type envelope struct {
	w, h, i int
}

type input struct {
	n int
	w, h int
	es []envelope
}

type output struct {
	ary []int
	memo []int
	crumbs []int
	max_len, max_idx int
}

func read_input() *input {
	result := &input{}
	r := bufio.NewReader(os.Stdin)

	fmt.Fscanf(r, "%d %d %d\n", &result.n, &result.w, &result.h)

	result.es = make([]envelope, result.n)

	for i := 0; i < result.n; i++ {
		result.es[i].i = i + 1
		fmt.Fscanf(r, "%d %d\n", &result.es[i].w, &result.es[i].h)
	}

	return result
}

func process_input(inp *input) *output {
	sort.Sort(ByArea(inp.es))

	out := &output{}
	out.max_len, out.max_idx = 0, -1
 	out.memo = make([]int, inp.n)

	// initialize the memo, taking into account that valid envelopes must be > postcard's dimensions
	for i := range out.memo {
		if inp.es[i].w > inp.w && inp.es[i].h > inp.h {
			out.memo[i] = 1
			if out.max_len == 0 {
				out.max_len = 1
				out.max_idx = i
			}
		}
 	}

	out.crumbs = make([]int, inp.n)
	for i := range out.crumbs {
		out.crumbs[i] = -1
	}

 	for i := 0; i < inp.n; i++ {
 		for j := 0; j < inp.n; j++ {
			if i == j {
				// we are not interested in link to ourselves
				continue
			}

			// ignore too small an envelope
			if inp.es[i].w <= inp.w || inp.es[i].h <= inp.h {
				continue
			}

			if inp.es[i].w < inp.es[j].w && inp.es[i].h < inp.es[j].h {
				// i -> j
				if out.memo[j] < out.memo[i] + 1 {
					out.memo[j] = out.memo[i] + 1
					out.crumbs[j] = i

					if out.memo[j] > out.max_len {
						out.max_len = out.memo[j]
						out.max_idx = j
					}
				}
			}
		}
	}

	out.ary = make([]int, out.max_len)
	for i, idx := out.max_len - 1, out.max_idx; i >= 0; i-- {
		out.ary[i] = inp.es[idx].i
		idx        = out.crumbs[idx]
	}

	return out
}

// ByAread implements sort.Interface for []envelope based on the area of the envelope.
type ByArea []envelope

func (a ByArea) Len() int           { return len(a) }
func (a ByArea) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByArea) Less(i, j int) bool { return a[i].w * a[i].h < a[j].w * a[j].h }

func main() {
	i := read_input()
//	fmt.Printf("%v\n", i)

	out := process_input(i)
	if (out.max_len == 0) {
		fmt.Printf("%d\n", out.max_len)
	} else {
		fmt.Printf("%d\n", out.max_len)
		idx, l := 0, len(out.ary)
		fmt.Printf("%d", out.ary[idx])
		for idx = 1; idx < l; idx++ {
			fmt.Printf(" %d", out.ary[idx])
		}
		fmt.Println()

	// 	arr := make([]int, out.max_len)
	// 	for i, idx := out.max_len - 1, out.max_idx; i >= 0; i-- {
	// 		arr[i] = idx
	// 		idx = out.crumbs[idx]
	// 	}

	// 	fmt.Printf("(%d, %d) -> ", i.w, i.h)
	// 	for j := range out.ary {
	// 		fmt.Printf("(%d, %d) -> ", i.es[arr[j]].w, i.es[arr[j]].h)
	// 	}
	}

//	fmt.Printf("%v\n", out)
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"sort"
)

type envelope struct {
	w, h, i int
}

type input struct {
	n int
	w, h int
	es []envelope
}

type output struct {
	ary []int
	memo []int
	crumbs []int
	max_len, max_idx int
}

func read_input() *input {
	result := &input{}
	r := bufio.NewReader(os.Stdin)

	fmt.Fscanf(r, "%d %d %d\n", &result.n, &result.w, &result.h)

	result.es = make([]envelope, result.n)

	for i := 0; i < result.n; i++ {
		result.es[i].i = i + 1
		fmt.Fscanf(r, "%d %d\n", &result.es[i].w, &result.es[i].h)
	}

	return result
}

func process_input(inp *input) *output {
	sort.Sort(ByArea(inp.es))

	out := &output{}
	out.max_len, out.max_idx = 0, -1
 	out.memo = make([]int, inp.n)

	// initialize the memo, taking into account that valid envelopes must be > postcard's dimensions
	for i := range out.memo {
		if inp.es[i].w > inp.w && inp.es[i].h > inp.h {
			out.memo[i] = 1
			if out.max_len == 0 {
				out.max_len = 1
				out.max_idx = i
			}
		}
 	}

	out.crumbs = make([]int, inp.n)
	for i := range out.crumbs {
		out.crumbs[i] = -1
	}

 	for i := 0; i < inp.n; i++ {
 		for j := 0; j < inp.n; j++ {
			if i == j {
				// we are not interested in link to ourselves
				continue
			}

			// ignore too small an envelope
			if inp.es[i].w <= inp.w || inp.es[i].h <= inp.h {
				continue
			}

			if inp.es[i].w < inp.es[j].w && inp.es[i].h < inp.es[j].h {
				// i -> j
				if out.memo[j] < out.memo[i] + 1 {
					out.memo[j] = out.memo[i] + 1
					out.crumbs[j] = i

					if out.memo[j] > out.max_len {
						out.max_len = out.memo[j]
						out.max_idx = j
					}
				}
			}
		}
	}

	out.ary = make([]int, out.max_len)
	for i, idx := out.max_len - 1, out.max_idx; i >= 0; i-- {
		out.ary[i] = inp.es[idx].i
		idx        = out.crumbs[idx]
	}

	return out
}

// ByArea implements sort.Interface for []envelope based on the area of the envelope.
type ByArea []envelope

func (a ByArea) Len() int           { return len(a) }
func (a ByArea) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByArea) Less(i, j int) bool { return a[i].w * a[i].h < a[j].w * a[j].h }

func main() {
	i := read_input()

	out := process_input(i)
	fmt.Printf("%d\n", out.max_len)
	if (out.max_len != 0) {
		idx, l := 0, len(out.ary)
		fmt.Printf("%d", out.ary[idx])
		for idx = 1; idx < l; idx++ {
			fmt.Printf(" %d", out.ary[idx])
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
	"strconv"
	"errors"
	"runtime"
	"sort"
)

type env struct {
	w, h, i int
	fits, holds map[*env]bool
}

func (e *env) ft(ee *env) bool {
	return e.w < ee.w && e.h < ee.h
}

func (e *env) String() string {
	return strconv.Itoa(e.i)
}

type envs []*env

func (slice envs) Len() int {
	return len(slice)
}

func (slice envs) Less(i, j int) bool {
	return len(slice[i].holds) < len(slice[j].holds);
}

func (slice envs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	n, w, h := nextInt(), nextInt(), nextInt()
	card := &env{w, h, 0, make(map[*env]bool), make(map[*env]bool)}
	all := make(map[*env]bool)
	for i := 0; i < n; i++ {
		ew, eh := nextInt(), nextInt()
		e := &env{ew, eh, i + 1, make(map[*env]bool), make(map[*env]bool)}
		if !card.ft(e) {
			continue
		}
		all[e] = true
	}
	runtime.GC()
	for e := range all {
		temp := make(map[*env]bool)
		for t := range all {
			temp[t] = true
		}
		for t := range temp {
			if e == t {
				continue
			}
			if e.ft(t) {
				t.holds[e] = true
				e.fits[t] = true
				for r := range e.fits {
					delete(temp, r)
					e.fits[r] = true
					r.holds[e] = true
				}
			}
		}
		runtime.GC()
	}
	var best *env = nil
	for e := range all {
		if best == nil || len(best.holds) < len(e.holds) {
			best = e
		}
		if e.i % 100 == 0 {
			runtime.GC()
		}
	}
	if best == nil {
		printf("0\n")
		return
	}
	runtime.GC()
	res := make(envs, 0)
	res = append(res, best)
	for e := range best.holds {
		res = append(res, e)
		if e.i % 100 == 0 {
			runtime.GC()
		}
	}
	sort.Sort(res)
	s := fmt.Sprintf("%v", res)
	printf("%d\n%s\n", len(res), s[1:len(s)-1])
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
	"strconv"
	"errors"
	"sort"
	"runtime"
)

type env struct {
	w, h, i int
}

func (e *env) ft(ee *env) bool {
	return e.w < ee.w && e.h < ee.h
}

func (e *env) String() string {
	return strconv.Itoa(e.i)
}

type envs []*env

func (slice envs) Len() int {
	return len(slice)
}

func (slice envs) Less(i, j int) bool {
	return slice[i].ft(slice[j])
}

func (slice envs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	n, w, h := nextInt(), nextInt(), nextInt()
	card := &env{w, h, 0}
	all := make(envs, 0)
	all = append(all, card)
	for i := 0; i < n; i++ {
		ew, eh := nextInt(), nextInt()
		e := &env{ew, eh, i + 1}
		if card.ft(e) {
			all = append(all, e)
		}
	}
	sort.Sort(all)
	runtime.GC()
	d := make([]int, len(all))
	p := make([]int, len(all))
	m, ps := 0, 0
	for i := 0; i < len(d); i++ {
		d[i] = 1
		p[i] = -1
		for j := 0; j < i; j++ {
			if all[j].ft(all[i]) {
				if d[i] < d[j] + 1 {
					d[i] = d[j] + 1
					p[i] = j
				}
				if d[i] > m {
					m = d[i]
					ps = i
				}
			}
		}
	}
	path := make([]int, 0)
	for ps != -1 {
		path = append([]int{all[ps].i}, path...)
		ps = p[ps]
	}
	path = path[1:]
	printf("%d\n", len(path))
	if len(path) > 0 {
		s := fmt.Sprintf("%v", path)
		printf("%s\n", s[1:len(s)-1])
	}

}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
	"strconv"
	"errors"
	"sort"
	"runtime"
)

type env struct {
	w, h, i int
}

func (e *env) ft(ee *env) bool {
	return e.w < ee.w && e.h < ee.h
}

func (e *env) String() string {
	return strconv.Itoa(e.i)
}

type envs []*env

func (slice envs) Len() int {
	return len(slice)
}

func (slice envs) Less(i, j int) bool {
	return slice[i].w * slice[i].h < slice[j].w * slice[j].h
}

func (slice envs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	n, w, h := nextInt(), nextInt(), nextInt()
	card := &env{w, h, 0}
	all := make(envs, 0)
	all = append(all, card)
	for i := 0; i < n; i++ {
		ew, eh := nextInt(), nextInt()
		e := &env{ew, eh, i + 1}
		if card.ft(e) {
			all = append(all, e)
		}
	}
	sort.Sort(all)
	runtime.GC()
	d := make([]int, len(all))
	p := make([]int, len(all))
	m, ps := 0, 0
	for i := 0; i < len(d); i++ {
		d[i] = 1
		p[i] = -1
		for j := 0; j < i; j++ {
			if all[j].ft(all[i]) {
				if d[i] < d[j] + 1 {
					d[i] = d[j] + 1
					p[i] = j
				}
				if d[i] > m {
					m = d[i]
					ps = i
				}
			}
		}
	}
	path := make([]int, 0)
	for ps != -1 {
		path = append([]int{all[ps].i}, path...)
		ps = p[ps]
	}
	path = path[1:]
	printf("%d\n", len(path))
	if len(path) > 0 {
		s := fmt.Sprintf("%v", path)
		printf("%s\n", s[1:len(s)-1])
	}

}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

//  URL: http://codeforces.com/contest/4/problem/D
//  PROBLEM RESTATEMENT
//      Let A be a set of envelopes, each envelope contains integer height and width.
//      Chain C is a subset of A, where C[i] height and width > C[i-1] height
//      and width.
//      Find the chain of maximum size.
//  CONSTRAINTS
//      1 <= n <= 5000, 1 <= w, h <= 10^6
//  APPROACH
//      (1) Discard all envelopes that Peter's card cannot fit into.
//      (2) Sort and call the remaining envelopes set E.
//      (3) At any given step, we need to find the minimum envelope that has
//          height and width greater than the current element.
//      (4) In O(n^2), we can compute the maximum chain length using DP:
//            * Initialize each element of dp with 1.
//            * dp[i] = max(dp[i-1], dp[i-2] ... dp[0]) + 1

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type Envelope struct {
	Width  int
	Height int
	Child  int
	Number int
}

func solve(dp []int, e []Envelope) []int {
	// Solve the DP recurrence.
	for i := 1; i < len(dp); i++ {
		for j := 0; j < i; j++ {
			if e[i].Width > e[j].Width && e[i].Height > e[j].Height {
				if dp[j]+1 > dp[i] {
					dp[i] = dp[j] + 1
					e[i].Child = j
				}
			}
		}
	}
	// Find max element of DP - the length and final index of the chain.
	maxChainIndex := 0
	maxChainLength := 0
	for i := 0; i < len(dp); i++ {
		if dp[i] > maxChainLength {
			maxChainLength = dp[i]
			maxChainIndex = i
		}
	}
	if maxChainLength == 0 {
		return []int{}
	}
	// Follow the children to find the envelopes in the largest chain.
	var ans []int
	for maxChainIndex != -1 {
		ans = append(ans, e[maxChainIndex].Number)
		maxChainIndex = e[maxChainIndex].Child
	}
	return ans
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n, w, h int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &w, &h)
	var dp []int
	var e []Envelope
	for i := 0; i < n; i++ {
		var wi, hi int
		fmt.Fscanf(reader, "%d %d\n", &wi, &hi)
		if wi > w && hi > h {
			e = append(e, Envelope{wi, hi, -1, i + 1})
			dp = append(dp, 1)
		}
	}
	sort.Slice(e, func(i, j int) bool {
		if e[i].Width < e[j].Width {
			return true
		} else if e[i].Height < e[j].Height {
			return true
		}
		return false
	})
	solution := solve(dp, e)
	l := len(solution)
	if l == 0 {
		fmt.Fprintf(writer, "%d\n", 0)
	} else {
		fmt.Fprintf(writer, "%d\n", l)
		for i := l - 1; i >= 0; i-- {
			fmt.Fprintf(writer, "%d ", solution[i])
		}
		fmt.Fprintf(writer, "\n")
	}
}


Consider a sequence of digits of length $$$2^k$$$ $$$[a_1, a_2, \ldots, a_{2^k}]$$$. We perform the following operation with it: replace pairs $$$(a_{2i+1}, a_{2i+2})$$$ with $$$(a_{2i+1} + a_{2i+2})\bmod 10$$$ for $$$0\le i<2^{k-1}$$$. For every $$$i$$$ where $$$a_{2i+1} + a_{2i+2}\ge 10$$$ we get a candy! As a result, we will get a sequence of length $$$2^{k-1}$$$.Less formally, we partition sequence of length $$$2^k$$$ into $$$2^{k-1}$$$ pairs, each consisting of 2 numbers: the first pair consists of the first and second numbers, the second of the third and fourth $$$\ldots$$$, the last pair consists of the ($$$2^k-1$$$)-th and ($$$2^k$$$)-th numbers. For every pair such that sum of numbers in it is at least $$$10$$$, we get a candy. After that, we replace every pair of numbers with a remainder of the division of their sum by $$$10$$$ (and don't change the order of the numbers).Perform this operation with a resulting array until it becomes of length $$$1$$$. Let $$$f([a_1, a_2, \ldots, a_{2^k}])$$$ denote the number of candies we get in this process. For example: if the starting sequence is $$$[8, 7, 3, 1, 7, 0, 9, 4]$$$ then:After the first operation the sequence becomes $$$[(8 + 7)\bmod 10, (3 + 1)\bmod 10, (7 + 0)\bmod 10, (9 + 4)\bmod 10]$$$ $$$=$$$ $$$[5, 4, 7, 3]$$$, and we get $$$2$$$ candies as $$$8 + 7 \ge 10$$$ and $$$9 + 4 \ge 10$$$.After the second operation the sequence becomes $$$[(5 + 4)\bmod 10, (7 + 3)\bmod 10]$$$ $$$=$$$ $$$[9, 0]$$$, and we get one more candy as $$$7 + 3 \ge 10$$$. After the final operation sequence becomes $$$[(9 + 0) \bmod 10]$$$ $$$=$$$ $$$[9]$$$. Therefore, $$$f([8, 7, 3, 1, 7, 0, 9, 4]) = 3$$$ as we got $$$3$$$ candies in total.You are given a sequence of digits of length $$$n$$$ $$$s_1, s_2, \ldots s_n$$$. You have to answer $$$q$$$ queries of the form $$$(l_i, r_i)$$$, where for $$$i$$$-th query you have to output $$$f([s_{l_i}, s_{l_i+1}, \ldots, s_{r_i}])$$$. It is guaranteed that $$$r_i-l_i+1$$$ is of form $$$2^k$$$ for some nonnegative integer $$$k$$$.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the sequence. The second line contains $$$n$$$ digits $$$s_1, s_2, \ldots, s_n$$$ ($$$0 \le s_i \le 9$$$). The third line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. Each of the next $$$q$$$ lines contains two integers $$$l_i$$$, $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) — $$$i$$$-th query. It is guaranteed that $$$r_i-l_i+1$$$ is a nonnegative integer power of $$$2$$$.

Output $$$q$$$ lines, in $$$i$$$-th line output single integer — $$$f([s_{l_i}, s_{l_i + 1}, \ldots, s_{r_i}])$$$, answer to the $$$i$$$-th query.

NoteThe first example illustrates an example from the statement.$$$f([7, 3, 1, 7]) = 1$$$: sequence of operations is $$$[7, 3, 1, 7] \to [(7 + 3)\bmod 10, (1 + 7)\bmod 10]$$$ $$$=$$$ $$$[0, 8]$$$ and one candy as $$$7 + 3 \ge 10$$$ $$$\to$$$ $$$[(0 + 8) \bmod 10]$$$ $$$=$$$ $$$[8]$$$, so we get only $$$1$$$ candy.$$$f([9]) = 0$$$ as we don't perform operations with it.

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func max(a,b int) int {
	if a>b {
		return a
	} else {
		return b
	}
}
func min(a,b int) int {
	if a>b {
		return b
	} else {
		return a
	}
}

const L,N uint=17,100050

var table [L][N]int
var a,sum [N]int
func get(l,r int) int {
	ans:=sum[r]-sum[l-1]
	if ans<0 {
		return ans+10
	} else {
		return ans
	}
}
func main() {

	defer writer.Flush()

	var n int
	scanf("%d\n",&n)
	for i:=1;i<=n;i++ {
		scanf("%d ",&a[i])
		sum[i]=(sum[i-1]+a[i])%10
	}
	scanf("\n")

	var j uint
	for j=1;j<L;j++ {
		for i:=1;i<=n-(1<<j)+1;i++ {
			table[j][i]=table[j-1][i]+table[j-1][i+(1<<(j-1))]
			if get(i,i+(1<<(j-1))-1)+get(i+(1<<(j-1)),i+(1<<j)-1)>=10 {
				table[j][i]++
			}
			//printf("(%d %d) %d\n",i,i+(1<<j)-1,table[j][i])
		}
	}

	var q int
	scanf("%d\n",&q)
	for ;q>0;q-- {
		var l,r int
		scanf("%d %d\n",&l,&r)
		log:=0
		for sz:=r-l+1;sz>1;sz/=2 {
			log++
		}
		printf("%d\n",table[log][l])
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const k = 20

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscan(reader, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}

	res := make([][]int, n)
	candies := make([][]int, n)
	for i := 0; i < n; i++ {
		res[i] = make([]int, k)
		candies[i] = make([]int, k)

		res[i][0] = a[i]
		candies[i][0] = 0
	}

	var j uint8 = 1
	for j < k {
		for i := 0; i + (1 << j) <= n; i++ {
			temp := res[i][j-1] + res[i+(1 << (j-1))][j-1]
			res[i][j] = temp % 10
			candies[i][j] = candies[i][j-1] + candies[i+(1 << (j-1))][j-1] + temp / 10
		}
		j++
	}

	var q int
	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		var l, r int
		fmt.Fscan(reader, &l, &r)
		j = k
		for {
			if l - 1 + (1 << j) == r {
				fmt.Fprintln(writer, candies[l - 1][j])
				break
			}
			j--
		}
	}
}

package main

import (
    "bufio"
    "fmt"
    "os"
)

type RSQ struct {
    prefixSum []int
}

func NewRSQ(n int, a []int) *RSQ {
    rsq := RSQ{
        prefixSum: make([]int, n + 1),
    }
    for i := 0; i < n; i++ {
        rsq.prefixSum[i + 1] = rsq.prefixSum[i] + a[i]
    }
    return &rsq
}

func (rsq *RSQ) query(l int, r int) int {
    return (rsq.prefixSum[r] - rsq.prefixSum[l - 1]) / 10
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()

    var n, m int
    fmt.Fscan(reader, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(reader, &a[i])
    }
    rsq := NewRSQ(n, a)

    fmt.Fscan(reader, &m)
    for i := 0; i < m; i++ {
        var l, r int
        fmt.Fscan(reader, &l, &r)
        fmt.Fprintln(writer, rsq.query(l, r))
    }

}

// Author: sighduck
// URL: https://codeforces.com/contest/1189/problem/C

package main

import (
	"bufio"
	"fmt"
	"os"
)

type Query struct {
	L int
	R int
}

func Solve(n int, s []int, queries []Query) []int {
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		dp[i] = s[i]
		if i > 0 {
			dp[i] += dp[i-1]
		}
	}
	answers := []int{}
	for _, query := range queries {
		l, r := query.L-1, query.R-1
		if l == 0 {
			answers = append(answers, dp[r]/10)
		} else {
			answers = append(answers, (dp[r]-dp[l-1])/10)
		}
	}
	return answers
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &s[i])
	}
	fmt.Fscanf(reader, "\n")
	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	queries := make([]Query, q)
	for i := 0; i < q; i++ {
		fmt.Fscanf(reader, "%d %d\n", &queries[i].L, &queries[i].R)
	}

	results := Solve(n, s, queries)
	for _, result := range results {
		fmt.Fprintf(writer, "%d\n", result)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const k = 20

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscan(reader, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}

    fmt.Println(a)
	res := make([][]int, n, k)
	candies := make([][]int, n, k)
	for i := 0; i < n; i++ {
		res[i] = make([]int, k)
		candies[i] = make([]int, k)

		res[i][0] = a[i]
		candies[i][0] = 0
	}

	var j uint8 = 1
	for j < k {
		for i := 0; i + (1 << j) <= n; i++ {
			temp := res[i][j-1] + res[i+(1 << (j-1))][j-1]
			res[i][j] = temp % 10
			candies[i][j] = candies[i][j-1] + candies[i+(1 << (j-1))][j-1] + temp / 10
		}
		j++
	}

	var q int
	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		var l, r int
		fmt.Fscan(reader, &l, &r)
		j = k
		for {
			if l - 1 + (1 << j) == r {
				fmt.Fprintln(writer, candies[l - 1][j])
				break
			}
			j--
		}
	}
}