package main

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

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

type pqe struct {
	v interface{}
	p int
}
type Pq []pqe

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}
func init() {
	sc.Split(bufio.ScanWords)
}
func (pq *Pq) size() int { return len(*pq) - 1 }
func (pq *Pq) heapify(i int) {
	for {
		lc, rc := 2*i, 2*i+1
		var x int
		if lc < len(*pq) && (*pq)[lc].p > (*pq)[i].p {
			x = lc
		} else {
			x = i
		}
		if rc < len(*pq) && (*pq)[rc].p > (*pq)[x].p {
			x = rc
		}
		if x == i {
			break
		}
		(*pq)[i], (*pq)[x] = (*pq)[x], (*pq)[i]
		i = x
	}
}
func (pq *Pq) insert(v int, p int) {
	*pq = append(*pq, pqe{v: v, p: p})
	for i := len(*pq) - 1; i > 1 && (*pq)[i].p > (*pq)[i/2].p; i = i / 2 {
		(*pq)[i], (*pq)[i/2] = (*pq)[i/2], (*pq)[i]
	}
}
func (pq *Pq) extract() interface{} {
	if len(*pq) <= 1 {
		return nil
	}
	me := (*pq)[1]
	(*pq)[1] = (*pq)[len(*pq)-1]
	*pq = (*pq)[:len(*pq)-1]
	(*pq).heapify(1)
	return me.v
}
func (pq *Pq) clear() { *pq = (*pq)[:1] }
func newPq(c int) Pq {
	p := make(Pq, 1, c)
	p[0] = pqe{v: -1, p: -1}
	return p
}
func (pq *Pq) peek() interface{} {
	if len(*pq) <= 1 {
		return nil
	}
	return (*pq)[1].v
}

func main() {
	n, m := ri(), ri()
	ab := make([][]int, 1e5+10)
	for i := 0; i < n; i++ {
		a, b := ri(), ri()
		ab[a] = append(ab[a], b)
	}
	ans := 0
	pq := newPq(1e5)
	for i := 1; i <= m; i++ {
		for _, v := range ab[i] {
			pq.insert(v, v)
		}
		if get, ok := pq.extract().(int); ok {
			ans += get
		}
	}
	fmt.Println(ans)
}


package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

type Task struct {
	a int
	b int
}

type sortTasks []Task

func (s sortTasks) Less(i, j int) bool {
	if s[i].a == s[j].a {
		return s[i].b > s[j].b
	}
	return s[i].a < s[j].a
}

func (s sortTasks) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s sortTasks) Len() int {
	return len(s)
}

func main() {
	n, m := scanInt(), scanInt()
	tasks := make([]Task, n)
	for i := 0; i < n; i++ {
		tasks[i] = Task{scanInt(), scanInt()}
	}
	answer := maxRevenue(n, m, tasks)
	fmt.Println(answer)
}

func debug(a ...interface{}) {
	// fmt.Println(a...)
}

func maxRevenue(n, m int, tasks []Task) int {
	sort.Sort(sortTasks(tasks))
	edges := make([]int, m+1)
	for i := 0; i < m+1; i++ {
		edges[i] = -1
	}

	for i, nextEdge := 0, 1; i < n && nextEdge <= m; {
		debug(i, nextEdge, tasks[i])
		if tasks[i].a == nextEdge {
			edges[nextEdge] = i
			nextEdge++
			continue
		} else if tasks[i].a > nextEdge {
			nextEdge++
		} else {
			i++
		}
	}
	revenue := 0
	debug(edges)
	debug(tasks)
	// 5 3 1
	// 4 2
	for i := 1; i <= m; i++ {
		maxForDay := 0
		selected := -1
		debug("search task for day ", i)
		for j := i; j > 0; j-- {
			debug(edges)
			if edges[j] == -1 {
				continue
			}
			t := tasks[edges[j]]
			if t.a <= j && t.b > maxForDay {
				maxForDay = tasks[edges[j]].b
				selected = j
			}
		}
		if selected != -1 {
			debug("selected", selected)
			debug("selected for day ", i, " :", selected, tasks[edges[selected]])
			edges[selected]++
			revenue += maxForDay
		}
	}
	return revenue
}


package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

type Task struct {
	a int
	b int
}

type sortTasks []Task

func (s sortTasks) Less(i, j int) bool {
	if s[i].b == s[j].b {
		return s[i].a > s[j].a
	}
	return s[i].b > s[j].b
}

func (s sortTasks) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s sortTasks) Len() int {
	return len(s)
}

func main() {
	n, m := scanInt(), scanInt()
	tasks := make([]Task, n)
	for i := 0; i < n; i++ {
		tasks[i] = Task{scanInt(), scanInt()}
	}
	answer := maxRevenue(n, m, tasks)
	fmt.Println(answer)
}

func debug(a ...interface{}) {
	// fmt.Println(a...)
}

func maxRevenue(n, m int, tasks []Task) int {
	sort.Sort(sortTasks(tasks))
	revenue := 0
	index := 0
	debug(tasks)
	for i := m; i > 0; i-- {
		debug("i:", i)
		for ; index < n; index++ {
			if tasks[index].a <= i {
				revenue += tasks[index].b
				index++
				break
			}
		}
	}
	return revenue
}


package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

type Task struct {
	a int
	b int
}

type sortTasks []Task

func (s sortTasks) Less(i, j int) bool {
	if s[i].b == s[j].b {
		return s[i].a > s[j].a
	}
	return s[i].b > s[j].b
}

func (s sortTasks) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s sortTasks) Len() int {
	return len(s)
}

func main() {
	n, m := scanInt(), scanInt()
	tasks := make([]Task, n)
	for i := 0; i < n; i++ {
		tasks[i] = Task{scanInt(), scanInt()}
	}
	answer := maxRevenue(n, m, tasks)
	fmt.Println(answer)
}

func debug(a ...interface{}) {
	// fmt.Println(a...)
}

func maxRevenue(n, m int, tasks []Task) int {
	sort.Sort(sortTasks(tasks))
	revenue := 0
	index := 0
	debug(tasks)
	for i := m; i > 0; i-- {
		debug("i:", i)
		for j := index; j < n; j++ {
			debug(i, j, tasks[j])
			if tasks[j].a <= i {
				revenue += tasks[j].b
				index = j + 1
				break
			}
			index = j
		}
	}
	return revenue
}


N, M = gets.split.map(&:to_i)
S = N.times.map { gets.split.map(&:to_i) }.sort_by{|v| -v[1] }
bitset = Array.new(M + 1, &:itself) # a variant of Union Find Tree.

class << bitset
  def next_clear_bit(base)
    return size if base >= size
    return base if self[base] == base
    self[base] = next_clear_bit(self[base])
  end

  def extend_trailling_set_bits(base)
    r = next_clear_bit(base)
    return nil if r >= size
    self[r] = r + 1
    r
  end
end

puts S.inject(0){|s, (a, b)| bitset.extend_trailling_set_bits(a) ? s + b : s }


N, M = gets.split.map(&:to_i)
S = N.times.map { gets.split.map(&:to_i) }.sort_by{|v| -v[1] }
bitset = Array.new(M + 1, &:itself) # a variant of Union Find Tree.

class << bitset
  def next_clear_bit(base)
    return size if base >= size
    return base if self[base] == base
    self[base] = next_clear_bit(self[base])
  end

  def extend_trailling_set_bits(base)
    r = next_clear_bit(base)
    return nil if r >= size
    self[r] = next_clear_bit(r + 1)
    r
  end
end

puts S.inject(0){|s, (a, b)| bitset.extend_trailling_set_bits(a) ? s + b : s }


(N,M),*AB = $<.map{|ln| ln.split.map(&:to_i) }

g, *W = 0, *0..M
D = lambda{|d|
	return M < d ? M : W[d] == d ? d : W[d] = D[W[d]]
}
AB.sort_by{|*,b|-b}.each{|a,b|
	next if M == d = D[a-1]
	g, W[d] = g+b, d+1
}
p g


class PriorityQueue
  attr_accessor(:node)

  def initialize(src = [])
    @node = []
    src.each do |e|
      push(e)
    end
  end

  def push(x)
    @node << x
    bottom_up
  end

  def pop
    res = @node.first
    top_down
    return res
  end

  def bottom_up
    i = @node.size - 1
    v = @node[i]
    while i > 0
      parent = (i - 1) >> 1
      break if @node[parent] >= v

      @node[parent], @node[i] = @node[i], @node[parent]
      i = parent
    end

    @node[i] = v
  end

  def top_down
    i = 0
    tmp = @node.pop
    while (i << 1) + 1 < @node.size
      lhs = (i << 1) + 1
      rhs = (i << 1) + 2
      m = lhs

      if rhs < @node.size && @node[lhs] < @node[rhs]
        m = rhs
      end

      break if @node[m] <= tmp
      @node[i] = @node[m]
      i = m
    end

    @node[i] = tmp unless @node.empty?
  end
end

n, m = $stdin.readline.chomp.split.map(&:to_i)
t = Array.new(m) { Array.new }
n.times do
  a, b = $stdin.readline.chomp.split.map(&:to_i)
  t[a - 1] << b
end

res = 0
pq = PriorityQueue.new
m.times do |i|
  t[i].each do |b|
    pq.push(b)
  end

  if !pq.node.empty?
    res += pq.pop
  end
end
puts res


class SkewHeap
  def initialize(rev = nil)
    @rev = rev
  end
  def push(k)
    @root = meld(@root, Node.new(k))
  end
  def top
    @root.key
  end
  def empty?
    @root.nil?
  end
  def pop
    key = @root.key
    @root = meld(@root.lchild, @root.rchild)
    key
  end
  def meld(lhs, rhs)
    return lhs unless rhs
    return rhs unless lhs
    lhs, rhs = rhs, lhs unless lhs < rhs
    lhs, rhs = rhs, lhs if @rev
    lhs.rchild = meld(lhs.rchild, rhs)
    lhs.lchild, lhs.rchild = lhs.lchild, lhs.rchild
    lhs
  end
  class Node
    include Comparable
    attr_accessor :key, :lchild, :rchild
    def initialize(k)
      @key = k
    end
    def <=>(other)
      @key <=> other.key
    end
  end
end

N,M=gets.split.map(&:to_i)
X=N.times.map{gets.split.map(&:to_i)}.sort{|l,r|l[0]<=>r[0]}
a=0
q=SkewHeap.new(true)
(1..M).each do |i|
  q.push(X.shift[1]) until X.empty? || i<X.first[0]
  a+=q.pop unless q.empty?
end
p a


n, m = gets.chomp.split.map(&:to_i)
hs = Hash.new
ar = []

n.times do
  a, b = gets.chomp.split.map(&:to_i)
  hs[a] ||= []
  hs[a] << b
end

res = 0
m.times do |i|
  ar.push(*hs[i + 1])
  if !ar.empty?
    ar.sort!
    res += ar.pop
  end
end
puts res


// https://atcoder.jp/contests/abc137/tasks/abc137_d
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize, m: usize,
        jobs: [(usize, i64); n]
    };

    let mut bucket = vec![vec![]; m];
    for (day, profit) in jobs {
        if m >= day {
            bucket[m-day].push(profit);
        }
    }

    let mut total = 0;
    let mut pq = BinaryHeap::new();
    for i in (0..m).rev() {
        for &p in &bucket[i] {
            pq.push(p);
        }
        if let Some(x) = pq.pop() {
            total += x;
        }
    }
    println!("{}", total);
}


// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }

    let n = get!(usize);
    let m = get!(usize);
    let mut ws = vec![vec![]; m];
    for _ in 0 .. n {
        let a = get!(usize);
        let b = get!();
        if a <= m {
            ws[a-1].push(b);
        }
    }
    let mut pq = std::collections::BinaryHeap::new();
    let mut ans = 0;
    for i in 0 .. ws.len() {
        for &w in ws[i].iter() {
            pq.push(w);
        }
        if let Some(w) = pq.pop() {
            ans += w;
        }
    }
    println!("{}", ans);
}


#[derive(Debug)]
struct UnionFindBitset { bitset: Vec<usize> }
impl UnionFindBitset {
  fn new(size: usize) -> UnionFindBitset {
    let mut bitset = (0 .. size).collect::<Vec<usize>>();
    UnionFindBitset{ bitset: bitset }
  }

  fn next_clear_bit(&mut self, base : usize) -> Option<usize> {
    if base >= self.bitset.len() {
      None
    } else if base == self.bitset[base] {
      Some(base)
    } else {
      let t = self.bitset[base];
      let r = self.next_clear_bit(t);
      self.bitset[base] = r.unwrap_or(self.bitset.len());
      r
    }
  }

  fn extend_bits(&mut self, base : usize) ->  Option<usize> {
    let r = self.next_clear_bit(base);
    if r.is_none() { return r; }
    let i = r.unwrap();
    let j = self.next_clear_bit(i + 1).unwrap_or(self.bitset.len());
    self.bitset[i] = j;
    r
  }
}

fn main(){
  let mut stdin = String::new();
  std::io::Read::read_to_string(
      &mut std::io::stdin(),
      &mut stdin).unwrap();
  let mut stdin = stdin.split_whitespace();
  let mut get = || stdin.next().unwrap();

  macro_rules! get {
      () => {
        (get().parse::<usize>().unwrap(), get().parse::<usize>().unwrap())
      };
  }

  let (n, m) = get!();

  let mut bitset = UnionFindBitset::new(m + 1);
  let mut jobs = Vec::with_capacity(n);

  for i in 0 .. n {
    jobs.push(get!());
  }
  jobs.sort_by_key(|x| x.1 );
  jobs.reverse();
  let mut ans = 0;

  for j in jobs.into_iter() {
    if let Some(_) = bitset.extend_bits(j.0) {
      ans += j.1;
    }
  }

  print!("{}", ans)
}


use proconio::input;

fn main() {
  input! {
    n: usize,
    m: usize,
    mut abs: [(usize,usize);n]
  }
  abs.sort_by(|a, b| a.1.cmp(&b.1));
  abs.reverse();

  let mut result = 0;
  for i in 0..=m {
    for mut a in abs.iter_mut() {
      if a.0 <= i {
        result += a.1;
        a.0 = usize::max_value();
        break
      }
    }
  }

  println!("{}", result);
}


use proconio::input;
use std::cmp::Ordering;

fn main() {
  input! {
    n: usize,
    m: usize,
    mut abs: [(usize,usize);n]
  }
  abs.sort_by(|a, b| {
    let result = a.1.cmp(&b.1);
    if result == Ordering::Equal {
      a.0.cmp(&b.0)
    } else {
      result
    }
  });
  abs.reverse();

  let mut result = 0;
  let mut index = m;
  let mut abs_index = 0;
  while 0 < index {
    while abs_index < n {
      let (day, val) = abs[abs_index];
      abs_index += 1;
      if day <= index {
        result += val;
        break
      }
    }
    index -= 1;
  }

  println!("{}", result);
}


use proconio::input;

fn main() {
  input! {
    n: usize,
    m: usize,
    mut abs: [(usize,usize);n]
  }
  abs.sort_by(|a, b| a.1.cmp(&b.1));
  abs.reverse();

  let mut result = 0;
  let mut index = m;
  let mut abs_index = 0;
  while 0 < index {
    while abs_index < n {
      let (day, val) = abs[abs_index];
      abs_index += 1;
      if day <= index {
        result += val;
        break
      }
    }
    index -= 1;
  }

  println!("{}", result);
}


import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let nm = readWords { Int($0)! }
    let n = nm[0]
    let m = nm[1]

    let ab: [(Int, Int)] = (1...n).map { _ in
        let ab = readWords { Int($0)! }
        return (ab[0], ab[1])
    }.sorted(by: <)

    var ans = 0
    var pq = PriorityQueue<Int>(<=)
    var i = 0
    for day in 1...m {
        while i < n && ab[i].0 <= day {
            pq.push(ab[i].1)
            i += 1
        }
        if let b = pq.pop() {
            ans += b
        }
    }

    print(ans)
}

private struct PriorityQueue<T: Comparable> {
    private var data: [T]
    private var ordered: (T, T) -> Bool

    public var isEmpty: Bool {
        return data.isEmpty
    }

    public var count: Int {
        return data.count
    }

    init(_ order: @escaping (T, T) -> Bool) {
        self.data = []
        self.ordered = order
    }

    init<Seq: Sequence>(_ seq: Seq, _ order: @escaping (T, T) -> Bool) where Seq.Element == T {
        self.data = []
        self.ordered = order

        for x in seq {
            push(x)
        }
    }

    public mutating func pop() -> T? {
        return data.popLast().map { item in
            var item = item
            if !isEmpty {
                swap(&item, &data[0])
                siftDown()
            }
            return item
        }
    }

    public mutating func push(_ item: T) {
        let oldLen = count
        data.append(item)
        siftUp(oldLen)
    }

    private mutating func siftDown() {
        var pos = 0
        let end = count

        data.withUnsafeMutableBufferPointer { bufferPointer in
            let _data = bufferPointer.baseAddress!
            swap(&_data[0], &_data[end])

            var child = 2 * pos + 1
            while child < end {
                let right = child + 1
                if right < end && ordered(_data[child], _data[right]) {
                    child = right
                }
                swap(&_data[pos], &_data[child])
                pos = child
                child = 2 * pos + 1
            }
        }
        siftUp(pos)
    }

    private mutating func siftUp(_ pos: Int) {
        var pos = pos
        while pos > 0 {
            let parent = (pos - 1) / 2;
            if ordered(data[pos], data[parent]) {
                break
            }
            data.swapAt(pos, parent)
            pos = parent
        }
    }
}

extension PriorityQueue: Sequence, IteratorProtocol {
    mutating func next() -> T? {
        return pop()
    }
}

main()


import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let nm = readWords { Int($0)! }
    let n = nm[0]
    let m = nm[1]

    let ab: [(Int, Int)] = (1...n).map { _ in
        let ab = readWords { Int($0)! }
        return (ab[0], ab[1])
    }.sorted(by: <)

    var ans = 0
    var pq = PriorityQueue<Int>(>=)
    var i = 0
    for day in 1...m {
        while i < n && ab[i].0 <= day {
            pq.push(ab[i].1)
            i += 1
        }
        if let b = pq.pop() {
            ans += b
        }
    }

    print(ans)
}

private struct PriorityQueue<T> {
    private var data: [T]
    private var ordered: (T, T) -> Bool

    public var isEmpty: Bool {
        return data.isEmpty
    }

    public var count: Int {
        return data.count
    }

    init(_ order: @escaping (T, T) -> Bool) {
        self.data = []
        self.ordered = order
    }

    init<Seq: Sequence>(_ seq: Seq, _ order: @escaping (T, T) -> Bool) where Seq.Element == T {
        self.data = []
        self.ordered = order

        for x in seq {
            push(x)
        }
    }

    public mutating func pop() -> T? {
        return data.popLast().map { item in
            var item = item
            if !isEmpty {
                swap(&item, &data[0])
                siftDown()
            }
            return item
        }
    }

    public mutating func push(_ item: T) {
        let oldLen = count
        data.append(item)
        siftUp(oldLen)
    }

    private mutating func siftDown() {
        var pos = 0
        let end = count

        data.withUnsafeMutableBufferPointer { bufferPointer in
            let _data = bufferPointer.baseAddress!
            swap(&_data[0], &_data[end])

            var child = 2 * pos + 1
            while child < end {
                let right = child + 1
                if right < end && ordered(_data[right], _data[child]) {
                    child = right
                }
                swap(&_data[pos], &_data[child])
                pos = child
                child = 2 * pos + 1
            }
        }
        siftUp(pos)
    }

    private mutating func siftUp(_ pos: Int) {
        var pos = pos
        while pos > 0 {
            let parent = (pos - 1) / 2;
            if ordered(data[parent], data[pos]) {
                break
            }
            data.swapAt(pos, parent)
            pos = parent
        }
    }
}

extension PriorityQueue: Sequence, IteratorProtocol {
    mutating func next() -> T? {
        return pop()
    }
}

main()


import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}
struct PriorityQueue<T: Comparable> {
    private var data: [T]
    private var ordered: (T, T) -> Bool

    public var isEmpty: Bool {
        return data.isEmpty
    }

    public var count: Int {
        return data.count
    }

    init(_ order: @escaping (T, T) -> Bool) {
        self.data = []
        self.ordered = order
    }

    init<Seq: Sequence>(_ seq: Seq, _ order: @escaping (T, T) -> Bool) where Seq.Element == T {
        self.data = []
        self.ordered = order

        for x in seq {
            push(x)
        }
    }

    public mutating func pop() -> T? {
        return data.popLast().map { item in
            var item = item
            if !isEmpty {
                swap(&item, &data[0])
                siftDown()
            }
            return item
        }
    }

    public mutating func push(_ item: T) {
        let oldLen = count
        data.append(item)
        siftUp(oldLen)
    }

    private mutating func siftDown() {
        var pos = 0
        let end = count

        data.withUnsafeMutableBufferPointer { bufferPointer in
            let _data = bufferPointer.baseAddress!
            swap(&_data[0], &_data[end])

            var child = 2 * pos + 1
            while child < end {
                let right = child + 1
                if right < end && ordered(_data[child], _data[right]) {
                    child = right
                }
                swap(&_data[pos], &_data[child])
                pos = child
                child = 2 * pos + 1
            }
        }
        siftUp(pos)
    }

    private mutating func siftUp(_ pos: Int) {
        var pos = pos
        while pos > 0 {
            let parent = (pos - 1) / 2;
            if ordered(data[pos], data[parent]) {
                break
            }
            data.swapAt(pos, parent)
            pos = parent
        }
    }
}

extension PriorityQueue: Sequence, IteratorProtocol {
    mutating func next() -> T? {
        return pop()
    }
}

    let nm = readWords { Int($0)! }
    let n = nm[0]
    let m = nm[1]

    let ab: [(Int, Int)] = (1...n).map { _ in
        let ab = readWords { Int($0)! }
        return (ab[0], ab[1])
    }.sorted(by: <)

    var ans = 0
    var pq = PriorityQueue<Int>(<=)
    var i = 0
    for day in 1...m {
        while i < n && ab[i].0 <= day {
            pq.push(ab[i].1)
            i += 1
        }
        if let b = pq.pop() {
            ans += b
        }
    }

    print(ans)


import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

struct Pair: Comparable {
    var a: Int
    var b: Int
    static func <(lhs: Pair, rhs: Pair) -> Bool {
        return (lhs.b, lhs.a) < (rhs.b, rhs.a)
    }
}

func main() {
    let nm = readWords { Int($0)! }
    let n = nm[0]
    let m = nm[1]

    var q = PriorityQueue<Pair>(<=)
    for _ in 1...n {
        let ab = readWords { Int($0)! }
        q.push(Pair(a: ab[0], b: ab[1]))
    }

    var ans = 0
    var limit = m
    while let p = q.pop() {
        guard p.a <= limit else { continue }
        ans += p.b
        limit -= 1
    }

    print(ans)
}

private struct PriorityQueue<T: Comparable> {
    private var data: [T]
    private var ordered: (T, T) -> Bool

    public var isEmpty: Bool {
        return data.isEmpty
    }

    public var count: Int {
        return data.count
    }

    init(_ order: @escaping (T, T) -> Bool) {
        self.data = []
        self.ordered = order
    }

    init<Seq: Sequence>(_ seq: Seq, _ order: @escaping (T, T) -> Bool) where Seq.Element == T {
        self.data = []
        self.ordered = order

        for x in seq {
            push(x)
        }
    }

    public mutating func pop() -> T? {
        return data.popLast().map { item in
            var item = item
            if !isEmpty {
                swap(&item, &data[0])
                siftDown()
            }
            return item
        }
    }

    public mutating func push(_ item: T) {
        let oldLen = count
        data.append(item)
        siftUp(oldLen)
    }

    private mutating func siftDown() {
        var pos = 0
        let end = count

        data.withUnsafeMutableBufferPointer { bufferPointer in
            let _data = bufferPointer.baseAddress!
            swap(&_data[0], &_data[end])

            var child = 2 * pos + 1
            while child < end {
                let right = child + 1
                if right < end && ordered(_data[child], _data[right]) {
                    child = right
                }
                swap(&_data[pos], &_data[child])
                pos = child
                child = 2 * pos + 1
            }
        }
        siftUp(pos)
    }

    private mutating func siftUp(_ pos: Int) {
        var pos = pos
        while pos > 0 {
            let parent = (pos - 1) / 2;
            if ordered(data[pos], data[parent]) {
                break
            }
            data.swapAt(pos, parent)
            pos = parent
        }
    }
}

extension PriorityQueue: Sequence, IteratorProtocol {
    mutating func next() -> T? {
        return pop()
    }
}

main()


import Foundation
import CoreFoundation

#if swift(>=4.0)
prefix operator *
infix operator **: PowerPrecedence
precedencegroup PowerPrecedence {
    higherThan: MultiplicationPrecedence
    lowerThan: BitwiseShiftPrecedence
    associativity: right
}
#else
extension String {
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map{String($0)}
    }
    var count: Int {
        return self.characters.count
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted(by areInIncreasingOrder: (Element, Element) -> Bool = {$0 < $1}) -> [Element] {
        return self.sort(areInIncreasingOrder)
    }
    mutating func sort(by areInIncreasingOrder: (Element, Element) -> Bool = {$0 < $1}) {
        self.sortInPlace(areInIncreasingOrder)
    }
}
extension Array {
    mutating func swapAt(i: Int, _ j: Int) {
        swap(&self[i], &self[j])
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func reverse() {
        self = self.reversed()
    }
    func enumerated() -> EnumerateSequence<[Element]> {
        return self.enumerate()
    }
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
extension _ArrayType where Generator.Element == String {
    func joined(separator separator: String = "") -> String {
        return self.joinWithSeparator(separator)
    }
}
extension Range {
    func reversed() -> [Element] {
        return self.reverse()
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
prefix operator * { }
infix operator ** {
    precedence 155      // 乗除算より強く，ビットシフトより弱い
    associativity right // 右結合
}
#endif
protocol Container {
    associatedtype Item
    mutating func append(item: Item)
    var count: Int { get }
    subscript(i: Int) -> Item { get }
}
struct Stack<Element>: Container {
    var items = [Element]()
    mutating func push(item: Element) {
        items.append(item)
    }
    mutating func pop() -> Element {
        return items.removeLast()
    }
    mutating func append(item: Element) {
        self.push(item)
    }
    var count: Int {
        return items.count
    }
    subscript(i: Int) -> Element {
        return items[i]
    }
}
struct Queue<Element>: Container {
    var items = [Element]()
    mutating func push(item: Element) {
        items.append(item)
    }
    mutating func pop() -> Element {
        return items.removeFirst()
    }
    mutating func append(item: Element) {
        self.push(item)
    }
    var count: Int {
        return items.count
    }
    subscript(i: Int) -> Element {
        return items[i]
    }
}
struct Heap<Element: Comparable>: Container {
    var items = [Element]()
    mutating func push(item: Element) {
        var i = items.count
        while i > 0 {
            let p = (i - 1) / 2
            if items[p] <= item {
                break
            }
            if i == items.count {
                items.append(items[p])
            } else {
                items[i] = items[p]
            }
            i = p
        }
        if i == items.count {
            items.append(item)
        } else {
            items[i] = item
        }
    }
    mutating func pop() -> Element {
        let ret = items[0]
        let x = items[items.count - 1]
        var i: Int = 0
        while i * 2 + 1 < items.count - 1 {
            var a = i * 2 + 1
            let b = i * 2 + 2
            if b < items.count - 1 && items[b] < items[a] {
                a = b
            }
            if items[a] >= x {
                break
            }
            items[i] = items[a]
            i = a
        }
        items[i] = x
        _ = items.removeLast()
        return ret
    }
    mutating func append(item: Element) {
        self.push(item)
    }
    var count: Int {
        return items.count
    }
    subscript(i: Int) -> Element {
        return items[i]
    }
}
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: Character = " ") -> [String] {
    return readLine()!.split(separator: separator).map{String($0)}
}
func readIntSplit(by separator: Character = " ") -> [Int] {
    return readLine()!.split(separator: separator).map{Int($0)!}
}
prefix func * <T> (a: [T]) -> (T, T)             { return (a[0], a[1]) }
prefix func * <T> (a: [T]) -> (T, T, T)          { return (a[0], a[1], a[2]) }
prefix func * <T> (a: [T]) -> (T, T, T, T)       { return (a[0], a[1], a[2], a[3]) }
prefix func * <T> (a: [T]) -> (T, T, T, T, T)    { return (a[0], a[1], a[2], a[3], a[4]) }
prefix func * <T> (a: [T]) -> (T, T, T, T, T, T) { return (a[0], a[1], a[2], a[3], a[4], a[5]) }
func **(lhs: Int, rhs: Int) -> Int {
//    return (0..<rhs).reduce(1){i,_ in i*lhs}
    return Int(pow(Double(lhs), Double(rhs)))
}
func **(lhs: Int, rhs: Double) -> Double {
    return pow(Double(lhs), rhs)
}
func * <Element> (lhs: [Element], rhs: Int) -> [Element] {
    return (0..<rhs).reduce([]){a,_ in a+lhs}
//    return repeatElement(lhs, count: rhs)
}
func *(lhs: String, rhs: Int) -> String {
    return (0..<rhs).reduce(""){s,_ in s+lhs}
//    return repeatElement(lhs, count: rhs)
}
//func gcd(x: Int, _ y: Int) -> Int {
//    return y>0 ? gcd(y, x%y) : x
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}
let MOD = 10 ** 9 + 7

/*************** テストスペース ***************/

//arr.sort{$0.0==$1.0 ? $0.1<$1.1 : $0.0<$1.0}  // タプル配列のソート

/*************** メインプログラム ***************/

let (N, M) = *readIntSplit()
var tasks = [[Int]]() * (10**5+1)
for _ in 0..<N {
    let (A, B) = *readIntSplit()
    tasks[A-1] += [B]
}
var que = Heap<Int>()
var ans = 0
for i in 0..<M {
    for b in tasks[i] {
        que.push(-b)
    }
    if que.count > 0 {
        ans -= que.pop()
    }
}
print(ans)


import Foundation
import CoreFoundation

#if swift(>=4.0)
prefix operator *
infix operator **: PowerPrecedence
precedencegroup PowerPrecedence {
    higherThan: MultiplicationPrecedence
    lowerThan: BitwiseShiftPrecedence
    associativity: right
}
#else
extension String {
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map{String($0)}
    }
    var count: Int {
        return self.characters.count
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted(by areInIncreasingOrder: (Element, Element) -> Bool = {$0 < $1}) -> [Element] {
        return self.sort(areInIncreasingOrder)
    }
    mutating func sort(by areInIncreasingOrder: (Element, Element) -> Bool = {$0 < $1}) {
        self.sortInPlace(areInIncreasingOrder)
    }
}
extension Array {
    mutating func swapAt(i: Int, _ j: Int) {
        swap(&self[i], &self[j])
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func reverse() {
        self = self.reversed()
    }
    func enumerated() -> EnumerateSequence<[Element]> {
        return self.enumerate()
    }
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
extension _ArrayType where Generator.Element == String {
    func joined(separator separator: String = "") -> String {
        return self.joinWithSeparator(separator)
    }
}
extension Range {
    func reversed() -> [Element] {
        return self.reverse()
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
prefix operator * { }
infix operator ** {
    precedence 155      // 乗除算より強く，ビットシフトより弱い
    associativity right // 右結合
}
#endif
protocol Container {
    associatedtype Item
    mutating func append(item: Item)
    var count: Int { get }
    subscript(i: Int) -> Item { get }
}
struct Stack<Element>: Container {
    var items = [Element]()
    mutating func push(item: Element) {
        items.append(item)
    }
    mutating func pop() -> Element {
        return items.removeLast()
    }
    mutating func append(item: Element) {
        self.push(item)
    }
    var count: Int {
        return items.count
    }
    subscript(i: Int) -> Element {
        return items[i]
    }
}
struct Queue<Element>: Container {
    var items = [Element]()
    mutating func push(item: Element) {
        items.append(item)
    }
    mutating func pop() -> Element {
        return items.removeFirst()
    }
    mutating func append(item: Element) {
        self.push(item)
    }
    var count: Int {
        return items.count
    }
    subscript(i: Int) -> Element {
        return items[i]
    }
}
struct Heap<Element: Comparable>: Container {
    var items = [Element]()
    mutating func push(item: Element) {
        var i = items.count
        while i > 0 {
            let p = (i - 1) / 2
            if items[p] <= item {
                break
            }
            if i == items.count {
                items.append(items[p])
            } else {
                items[i] = items[p]
            }
            i = p
        }
        if i == items.count {
            items.append(item)
        } else {
            items[i] = item
        }
    }
    mutating func pop() -> Element {
        let ret = items[0]
        let x = items[items.count - 1]
        var i: Int = 0
        while i * 2 + 1 < items.count - 1 {
            var a = i * 2 + 1
            let b = i * 2 + 2
            if b < items.count - 1 && items[b] < items[a] {
                a = b
            }
            if items[a] >= x {
                break
            }
            items[i] = items[a]
            i = a
        }
        items[i] = x
        _ = items.removeLast()
        return ret
    }
    mutating func append(item: Element) {
        self.push(item)
    }
    var count: Int {
        return items.count
    }
    subscript(i: Int) -> Element {
        return items[i]
    }
}
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: Character = " ") -> [String] {
    return readLine()!.split(separator: separator).map{String($0)}
}
func readIntSplit(by separator: Character = " ") -> [Int] {
    return readLine()!.split(separator: separator).map{Int($0)!}
}
prefix func * <T> (a: [T]) -> (T, T)             { return (a[0], a[1]) }
prefix func * <T> (a: [T]) -> (T, T, T)          { return (a[0], a[1], a[2]) }
prefix func * <T> (a: [T]) -> (T, T, T, T)       { return (a[0], a[1], a[2], a[3]) }
prefix func * <T> (a: [T]) -> (T, T, T, T, T)    { return (a[0], a[1], a[2], a[3], a[4]) }
prefix func * <T> (a: [T]) -> (T, T, T, T, T, T) { return (a[0], a[1], a[2], a[3], a[4], a[5]) }
func **(lhs: Int, rhs: Int) -> Int {
//    return (0..<rhs).reduce(1){i,_ in i*lhs}
    return Int(pow(Double(lhs), Double(rhs)))
}
func **(lhs: Int, rhs: Double) -> Double {
    return pow(Double(lhs), rhs)
}
func * <Element> (lhs: [Element], rhs: Int) -> [Element] {
    return (0..<rhs).reduce([]){a,_ in a+lhs}
//    return repeatElement(lhs, count: rhs)
}
func *(lhs: String, rhs: Int) -> String {
    return (0..<rhs).reduce(""){s,_ in s+lhs}
//    return repeatElement(lhs, count: rhs)
}
//func gcd(x: Int, _ y: Int) -> Int {
//    return y>0 ? gcd(y, x%y) : x
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}
let MOD = 10 ** 9 + 7

/*************** テストスペース ***************/

//arr.sort{$0.0==$1.0 ? $0.1<$1.1 : $0.0<$1.0}  // タプル配列のソート

/*************** メインプログラム ***************/

let (N, M) = *readIntSplit()
var tasks = [[Int]()] * (10**5+1)
for _ in 0..<N {
    let (A, B) = *readIntSplit()
    tasks[A-1] += [B]
}
var que = Heap<Int>()
var ans = 0
for i in 0..<M {
    for b in tasks[i] {
        que.push(-b)
    }
    if que.count > 0 {
        ans -= que.pop()
    }
}
print(ans)


class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int(): number {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str(): string {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length: number): string[] {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  }
  ints(length: number): number[] {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  }
}
function divInt(a: number, b: number) {
  return Math.floor(a / b);
}
class Heap<T> {
  data: T[];
  compare: (a: T, b: T) => number;
  constructor(data: T[], compare: (a: T, b: T) => number) {
    data.sort(compare);
    this.data = data;
    this.compare = compare;
  }
  push(a: T): void {
    this.data.push(a);
    this._fixUp(this.data.length - 1);
  }
  _fixUp(pos: number): void {
    if (pos === 0) return;
    const parent = divInt(pos - 1, 2);
    if (this.compare(this.data[parent], this.data[pos]) < 0) {
      this._swap(parent, pos);
      this._fixUp(parent);
    }
  }
  _fixDown(pos: number): void {
    const leftSwapped =
      pos * 2 + 1 < this.data.length &&
      this.compare(this.data[pos], this.data[pos * 2 + 1]) < 0;
    const rightSwapped =
      pos * 2 + 2 < this.data.length &&
      this.compare(this.data[pos], this.data[pos * 2 + 2]) < 0;
    if (leftSwapped) {
      if (rightSwapped) {
        if (this.compare(this.data[pos * 2 + 1], this.data[pos * 2 + 2]) < 0) {
          this._swap(pos * 2 + 2, pos);
          this._fixDown(pos * 2 + 2);
        } else {
          this._swap(pos * 2 + 1, pos);
          this._fixDown(pos * 2 + 1);
        }
      } else {
        this._swap(pos * 2 + 1, pos);
        this._fixDown(pos * 2 + 1);
      }
    } else {
      if (rightSwapped) {
        this._swap(pos * 2 + 2, pos);
        this._fixDown(pos * 2 + 2);
      }
    }
  }
  _swap(a: number, b: number): void {
    [this.data[a], this.data[b]] = [this.data[b], this.data[a]];
  }
  /**
   * get maximum value.
   */
  pop(): T {
    if (this.data.length == 0) throw "Heap is empty!";
    const top = this.data[0];
    if (this.data.length > 1) {
      this.data[0] = this.data.pop();
      this._fixDown(0);
    }else{
      this.data.pop();
    }
    return top;
  }
  top(): T | void {
    if (this.data.length == 0) return undefined;
    return this.data[0];
  }
  empty(): boolean {
    return this.data.length == 0;
  }
  _debug(): void {
    console.log("Heap", JSON.stringify(this));
  }
}
function Main(_: NormalInput) {
  const [N, M] = _.ints(2);
  const AB = _.ints(2 * N);
  let A = AB.filter((_, i) => i % 2 == 0);
  let B = AB.filter((_, i) => i % 2 == 1);
  const Job = A.map((_, i) => [A[i], B[i]] as [number, number]);
  Job.sort((x, y) => y[0] - x[0]);
  const candidate = new Heap<[number, number]>([], (x, y) => x[1] - y[1]);
  let ans = 0;
  for (let day = 1; day <= M; day++) {
    while (Job.length > 0 && Job[Job.length - 1][0] <= day) {
      candidate.push(Job.pop());
    }
    if (!candidate.empty()) {
      // console.log("pop", candidate.top());
      ans += candidate.pop()[1];
    }
  }
  console.log(ans);
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

let reader = new Reader();

let [N, M] = reader.readInts();
let jobs: {reward: number, day: number}[] = [];

for(let i=0; i<N; i++) {
    let [day, reward] = reader.readInts();
    jobs.push({day: day, reward:reward});
}

jobs.sort((job0, job1) => {
    if (job1.reward > job0.reward)
        return 1;
    if (job1.reward < job0.reward)
        return -1;
    return job1.day-job0.day;
});
let totalReward = 0;
let today = 0;

for(let job of jobs) {
    if (job.day+today <= M) {
        totalReward += job.reward;
        today += 1;
    }
}

console.log(totalReward);


import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

let reader = new Reader();

let [N, M] = reader.readInts();
let jobs: {reward: number, day: number}[] = [];

for(let i=0; i<N; i++) {
    let [day, reward] = reader.readInts();
    jobs.push({day: day, reward:reward});
}

jobs.sort((job0, job1) => {
    if (job1.reward > job0.reward)
        return 1;
    if (job1.reward < job0.reward)
        return -1;
    return job1.day-job0.day;
});
let totalReward = 0;
let today = 0;
console.log(jobs);

for(let job of jobs) {
    if (job.day+today <= M) {
        totalReward += job.reward;
        today += 1;
    }
}

console.log(totalReward);


function main(input) {
  input = input.trim().split('\n');
  const [n, m] = input[0].split(' ').map(n => Number(n));
  const abs = input.slice(1).map(a => a.split(' ').map(b => Number(b)));
  const map = {};
  for (let i = 0; i < n; i++) {
    const [a, b] = abs[i];
    if (!map[a]) {
      map[a] = [];
    }
    map[a].push(b);
  }
  const ps = [];
  let result = 0;
  for (let i = 1; i <= m; i++) {
    if (map[i]) {
      ps.push(...map[i]);
    }
    if (!ps.length) continue;
    const max = Math.max(...ps);
    result += max;
    const index = ps.indexOf(max);
    ps.splice(index, 1);
  }
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

ans = -1
d = float('inf')
for i in range(n):
    b = abs(a - (t - 0.006 * h[i]))
    if b < d:
        d = b
        ans = i + 1

print(ans)


N = int(input())
T, A = map(int, input().split())
H = map(int, input().split())

t = [T - h * 0.006 for h in H]
ans = 10**9
for i in range(len(t)):
    if abs(t[i] - A) < ans:
        ans_i = i
        ans = abs(t[i] - A)
print(ans_i + 1)


N = int(input())
T, A = map(int, input().split(' '))
H = map(int, input().split(' '))

ans = -1
abs_val = 1e9

for i, v in enumerate(H):
  if abs_val > abs((T - v * 0.006) - A):
    abs_val = abs((T - v * 0.006) - A)
    ans = i
print(ans + 1)


n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
def avg_tmp(t, x):
  return t- x*0.006
ans, ans_index = 10000000, 0
for i in range(n):
  if abs(avg_tmp(t, h[i]) -a) < abs(ans-a):
         ans = abs(avg_tmp(t, h[i]))
         ans_index = i+1
print(ans_index)


n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
def avg_tmp(t, x):
  return t- x*0.006
ans, ans_index = 10000000, 0
for i in range(n):
  if abs(avg_tmp(t, h[i]) -a) <= abs(ans-a):
         ans = abs(avg_tmp(t, h[i]))
         ans_index = i+1
print(ans_index)


n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
def avg_tmp(t, x):
  return int(t- x*0.006)
ans, ans_index = 10000000, 0
for i in range(n):
  if abs(avg_tmp(t, h[i]) -a) <= abs(ans-a):
         ans = abs(avg_tmp(t, h[i]))
         ans_index = i
print(ans_index +1)


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = in.nextInt();
        int t = in.nextInt();
        int a = in.nextInt();
        int[] heights = new int[n];
        for(int i = 0; i < n; i++) {
        	heights[i] = in.nextInt();
        }
        double min = Double.MAX_VALUE;
        int idx = 0;

        for(int i = 0; i < n; i++) {
        	if(min > dist(t, heights[i], a)) {
        		min = dist(t, heights[i], a);
        		idx = i;
        	}
        }
        out.println(idx + 1);
    }

    double dist(int t, int h, int a) {
    	return Math.abs(a - (t - h * 0.006));
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedInputStream reader = new BufferedInputStream(System.in);
    private byte[] buffer = new byte[0x8000];
    private int i = 0;
    private int length = 0;

    private int read() {
        if (i == length) {
            i = 0;
            try {
                length = reader.read(buffer);
            } catch (IOException ignored) {
            }
            if (length == -1) {
                return -1;
            }
        }
        return buffer[i++];
    }

    String next() {
        StringBuilder builder = new StringBuilder();
        int b = read();
        while (b < '!' || '~' < b) {
            b = read();
        }
        while ('!' <= b && b <= '~') {
            builder.appendCodePoint(b);
            b = read();
        }
        return builder.toString();
    }

    int nextInt() {
        return (int)nextLong();
    }

    long nextLong() {
        int b = read();
        while (b < '!' || '~' < b) {
            b = read();
        }
        int i = 0;
        if (b == '-') {
            i = 1;
            b = read();
        }
        long n = 0;
        while ('0' <= b && b <= '9') {
            n = n * 10 + b - '0';
            b = read();
        }
        return i == 0 ? n : -n;
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc;
	static PrintWriter out;
	public static void main(String[] args){
		sc = new FastScanner();
		out = new PrintWriter(System.out);
//		solve();
		out.println(solve());
		out.flush();
	}

	static int solve(){
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();
		double min = Integer.MAX_VALUE;
		double tmp = 0;
		int idx = 0;
		for(int i=1;i<=N;i++){
			tmp = Math.abs(A- (T - sc.nextInt() * 0.006));
			if(tmp < min){
				idx = i;
				min = tmp;
			}
		}
		return idx;
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
}


// ABC112

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

/** B */
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int T =  sc.nextInt();
		int A = sc.nextInt();

		int[] ary = new int[N];
		for(int i = 0; i < N; i++) {
			ary[i] = sc.nextInt();
		}

		double tmp = 1000000000;
		int index = 0;

		for(int i = 0; i<N; i++) {
			if(Math.abs(A - ((double)T - 0.006*ary[i])) < tmp) {
				index = i;
				tmp = Math.abs(A - ((double)T - 0.006*ary[i]));
			}
		}

		//************************************/
		// ここから出力処理
		//************************************/
		PrintWriter out = new PrintWriter(System.out);

		out.println(index+1); // 0オリジン

		// 最後に必ずFlush
		out.flush();
	}
}

//
///** A*/
//public class Main {
//	public static void main(String[] args) {
//		FastScanner sc = new FastScanner();
//		int X = sc.nextInt();
//		int Y =  sc.nextInt();
//
//		//************************************/
//		// ここから出力処理
//		//************************************/
//		PrintWriter out = new PrintWriter(System.out);
//
//
//		out.println(X + (Y/2));
//
//		// 最後に必ずFlush
//		out.flush();
//	}
//}

///** テンプレート */
//public class Main {
//	public static void main(String[] args) {
//		FastScanner sc = new FastScanner();
//		int N = sc.nextInt();
//		int M =  sc.nextInt();
//
//		int[] ary = new int[N];
//		for(int i = 0; i < N; i++) {
//			ary[i] = sc.nextInt();
//		}
//
//		//************************************/
//		// ここから出力処理
//		//************************************/
//		PrintWriter out = new PrintWriter(System.out);
//
//
//		out.println("hoge");
//
//		// 最後に必ずFlush
//		out.flush();
//	}
//}

/** スキャン用 */
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    /** クラス内部用だよ */
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    /** クラス内部用だよ */
    private int readByte() {
    	if (hasNextByte()) {
    		return buffer[ptr++];
    	}else {
    		return -1;
    	}
    }

    /**
     * クラス内部用だよ
     * ASCII の文字の内、表示用の文字を返す関数
     *
     * @return 改行とか制御文字じゃない、表示用文字ならtrue
     * */
    private static boolean isPrintableChar(int c) {
    	return 33 <= c && c <= 126;
    }

    /**
     * @return 改行文字とか空白以外を除いた、次の文字があればtrue
     * */
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
    		ptr++;
    	}
    	return hasNextByte();
    }

    /**
     *
     * @return 次の文字列
     */
    public String next() {
        if (!hasNext()) {
        	throw new NoSuchElementException();
        }

        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    /**
     *
     * @return 次のLong
     */
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    /**
     *
     * @return 次のInt
     */
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    /**
     *
     * @return 次のDouble
     */
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final int t = fs.nextInt();
        final int a = fs.nextInt();
        int closestDist = (int) 1e9;
        int res = -1;
        for (int i = 0; i < n; i++) {
            int curr = t - (fs.nextInt() * 6) / 1000;
            if (Math.abs(curr - a) < closestDist) {
                closestDist = Math.abs(curr - a);
                res = i + 1;
            }
        }
        System.out.println(res);
    }

    static final class Utils {
        public static void shuffleSort(int[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffle(int[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void shuffle(long[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void swap(int[] arr, int i, int j) {
            final int t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        public static void swap(long[] arr, int i, int j) {
            final long t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


//package reedeka;
import java.util.*;
import java.io.*;
import java.math.*;

public class Palace {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n, t, a;
		n = sc.nextInt();
		t = sc.nextInt();
		a = sc.nextInt();
		int i;
		double tmp, temp, s;
		int index = 1;
		int h;
		h = sc.nextInt();
		temp = t - 0.006*h;
		tmp = Math.abs(a - temp);
		for(i=2; i<=n; i++) {
			h = sc.nextInt();
			temp = t - 0.006*h;
			s = Math.abs(a-temp);
			if(s<tmp) {
				tmp = s;
				index = i;
			}
		}
		System.out.println(index);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		double t = sc.nextDouble(), a = sc.nextDouble();
		double tem = Double.MAX_VALUE;
		int ans = 0;
		for(int i = 0; i < n; i++) {
			double h = sc.nextDouble();
			double ave = t - h * 0.006;
			if(tem > Math.abs(t - ave)) {
				tem = Math.abs(t - ave);
				ans = i+1;
			}
		}
		System.out.println(ans);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t, a;
    cin >> n >> t >> a;
    vector<int> h(n);
    int idx = -1, MIN = INF;
    rep(i, 0, n){
        cin >> h[i];
        int tmp = t * 1000 - h[i] * 6;
        if(abs(tmp - a * 1000) < MIN){
            MIN = abs(tmp - a * 1000);
            idx = i;
        }
    }
    cout << idx + 1 << endl;
}


#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, T, A;
    cin >> N >> T >> A;
    ll ans = -1;
    double diff = INT_MAX;
    for (ll i = 0; i < N; i++) {
        ll H;
        cin >> H;
        double t = T - H * 0.006;
        double d = abs(t - A);
        if (d < diff) {
            ans = i;
            diff = d;
        }
    }

    cout << ans + 1 << endl;
}


#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, t, a; cin >> n >> t >> a;
  t *= 1000, a *= 1000;
  V<> h(n); for (int i = 0; i < n; ++i) cin >> h[i];
  int res = -1, mn = 1e9;
  for (int i = 0; i < n; ++i) {
    if (mn > abs(t - 6 * h[i] - a)) {
      res = i;
      mn = abs(t - 6 * h[i] - a);
    }
  }
  cout << res + 1 << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    cout << fixed << setprecision(5);
    int n, t, a, h, res;
    vector<pair<float, int>>vec;
    cin >> n;
    cin >> t >> a;
    // vec.push_back(make_pair(a, 0));
    for(int i=0; i<n; i++){
      cin >> h;
      float ans=t-(h*0.006);
      vec.push_back(make_pair(ans, i));
    }
    int mn=1000000;
    sort(vec.rbegin(), vec.rend());
    for(int i=0; i<vec.size(); i++){
      // cout << vec[i]. first << " " << vec[i].second << endl;
      if(abs(vec[i].first-a)<mn){
        mn=abs(vec[i].first-a);
        res=vec[i].second;
      }
    }
    cout << res+1;
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    cout << fixed << setprecision(5);
    int n, t, a, h, res;
    vector<pair<float, int>>vec;
    cin >> n;
    cin >> t >> a;
    vec.push_back(make_pair(a, 0));
    for(int i=0; i<n; i++){
      cin >> h;
      float ans=t-(h*0.006);
      ans-=a;
      vec.push_back(make_pair(ans, i));
    }
    sort(vec.rbegin(), vec.rend());
    for(int i=0; i<vec.size(); i++){
      // cout << vec[i]. first << " " << vec[i].second << endl;
      if(vec[i].first==a){
        res=vec[i+1].second;
      }
    }
    cout << res+1;
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    cout << fixed << setprecision(5);
    int n, t, a, h, res;
    vector<pair<float, int>>vec;
    cin >> n;
    cin >> t >> a;
    vec.push_back(make_pair(a, 0));
    for(int i=0; i<n; i++){
      cin >> h;
      float ans=(t-h)*0.006;
      vec.push_back(make_pair(ans, i));
    }
    sort(vec.rbegin(), vec.rend());
    for(int i=0; i<vec.size(); i++){
      if(vec[i].first==a){
        res=vec[i+1].second;
      }
    }
    cout << res+1;
}


#include <stdio.h>
int main(){

    int N,i,a;
    double H[1000],Ta[1000],Tb[1000];
    double T,A,x,max=1000;

    scanf(" %d", &N);
    scanf(" %lf %lf", &T, &A);

    for(i = 0; i < N; ++i){
      scanf(" %lf", &H[i]);
    }

    for(i = 0; i < N; ++i){
      Ta[i] = T - H[i] * 0.006;
    }

    for(i = 0; i < N; ++i){
      x = A - Ta[i];
      if(x < 0){
        Tb[i] = Ta[i] - A;
      }
      else {
        Tb[i] = A - Ta[i];
      }
    }

    for(i = 0; i < N; ++i){
      if(Tb[i] < max){
        max = Tb[i];
        a = i + 1;
      }
    }

    printf("%d\n", a);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long n;
    long long t, a;
    long long ans;
    long long hi;
    long long minv = 1ll << 50ll;
    long long h;

    scanf("%lld", &n);
    scanf("%lld %lld", &t, &a); t *= 1000; a *= 1000;

    for (long long i = 0; i < n; i++) {
        scanf("%lld", &h);

        hi = t - h * 6;

        if (minv > abs(a - hi)) {
            minv = abs(a - hi);
            ans = i + 1;
        }
    }

    printf("%lld\n", ans);

    return 0;
}


#include<stdio.h>
#include<math.h>
int main(){
  int n,t,a,h1;
  scanf("%d\n",&n);
  scanf("%d %d\n", &t,&a);
  scanf("%d",&h1);
  int flag = 1;
  double t1=t-h1*0.006;
  for (int i = 2; i <= n; i++) {
    int h;
    scanf("%d", &h);
    double t0=t-h*0.006;
    if (fabs(a-t0)<fabs(a-t1)){
      flag = i;
      t1 = t0;
    }
  }
  printf("%d\n", flag);
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

long int gcd(long int a, long int b){
  long int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

int main(void){
  int n,t,a;
  scanf("%d%d%d",&n,&t,&a);
  int h[n+1];
  for(int i=0;i<n+1;i++){
    h[i]=0;
  }
  int min=1e8;
  int ans;
  for(int i=0;i<n;i++){
    scanf("%d",&h[i]);
    double deg=t-h[i]*0.006;
    if(deg-a<0){
      deg-=a;
      deg*=(-1);
    }else{
      deg-=a;
    }
    if(deg<min){
      min=deg;
      ans=i+1;
    }
  }
  printf("%d\n",ans);
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

long int gcd(long int a, long int b){
  long int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

int main(void){
  int n,t,a;
  scanf("%d%d%d",&n,&t,&a);
  int h[n+1];
  for(int i=0;i<n+1;i++){
    h[i]=0;
  }
  int min=1e8;
  int ans;
  for(int i=0;i<n;i++){
    scanf("%d",&h[i]);
    double dif=t-h[i]*0.006-a;
    if(dif<0){
      dif*=(-1);
    }
    if(dif<min){
      min=dif;
      ans=i+1;
    }
  }
  printf("%d\n",ans);
  return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int N;
    cin >> N;
    int T, A;
    cin >> T >> A;
    vector<int> H(N);
    for (int i = 0; i < N; i++) cin >> H[i];

    double min_diff = 999999;
    int min_idx = -1;
    for (int i = 0; i < N; ++i) {
        int h = H[i];
        double t = T - h * 0.006;
        if (min_diff > (abs(double(A) - double(t)))) {
            min_diff = abs(double(A) - double(t));
            min_idx = i;
        }
    }
    cout << min_idx + 1 << endl;
    return 0;
}


"use strict";

var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

function next() {
    return +cin[cid++];
} // number一個取得
function nextstr() {
    return cin[cid++];
} // 文字列一個取得
function nextbig() {
    return BigInt(cin[cid++]);
} // BigInteger一個取得
// 長さnの配列として取得。aは文字列フラグ
function nexts(n, a) {
    return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a);
}
// 長さnのBigInt配列として取得。
function nextsbig(n) {
    return cin.slice(cid, cid += n).map(a => BigInt(a));
}
// w個ずつを組にして長さhの配列。aは文字列フラグ。
function nextm(h, w, a) {
    var r = [],
        i = 0;
    if (a)
        for (; i < h; i++) r.push(cin.slice(cid, cid += w));
    else
        for (; i < h; i++) r.push(cin.slice(cid, cid += w).map(a => +a));
    return r;
}
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
function xArray(v) {
    var a = arguments,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + v + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
}

console.log(main().toString());

function main() {
    let n = next();
    let t = next();
    let a = next();
    let h = nexts(n);
    let target = (t - a) * 1000 / 6
    let ans = 0;
    let min = 100000;
    let diff = 100000;
    for (let i = 0; i < n; i++) {
        diff = Math.abs(target - h[i]);
        if (min > diff) {
            min = diff;
            ans = i + 1;
        }
    }
    return ans;
}


function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    tmp2 = input[1].split(" ");
    tmp3 = input[2].split(" ");
    T = parseInt(tmp2[0]);
    A = parseInt(tmp2[1]);
    var ans;
    var ansAmari;
	//文字列から10進数に変換するときはparseIntを使います
    for(i = 0;i < parseInt(input[0]);i++){
        kion = T - parseInt(tmp3[i]) * 0.006;
        amari = A - kion;
        if(ansAmari > Math.abs(amari) || i === 0){
            ans = i+1;
            ansAmari = Math.abs(amari);
        }
    }
	console.log('%d',ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
N = inp.shift() * 1
l = inp.shift().split(' ')
T = l.shift() * 1
A = l.shift() * 1
l = inp.shift().split(' ')
min = 10000
j = 0
for(i=0; i<N; i++) {
    abs = Math.abs(A - (T - (l[i] * 1) * 0.006))
    if (min > abs) {
        min = abs
        j = i
    }
}
console.log(j+1)


function main(input) {
  const args = input.split('\n');
  const ary2 = args[1].split(' ').map(n => parseInt(n, 10));
  const N = parseInt(args[0], 10); //候補地数
  const T = ary2[0]; //気温求めるパラメータ
  const A = ary2[1]; //理想気温
  const ary = args[2].split(' ').map(n => parseInt(n, 10));
  let min_gap; //理想気温に最も近い気温
  let idx; //敵地番号

  for (let i = 0; i < ary.length; i++) {
    if (ary[i] === 0) {
      idx = (i + 1);
      break;
    } else {
      ave = T - (ary[i] * 0.006); //平均気温
      gap = Math.abs(A - ave);
      if (!min_gap || min_gap > gap) {
        min_gap = gap;
        idx = i + 1; // 帳尻合わせ
      }
    }
  }

  console.log(idx);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
  const args = input.split('\n');
  const ary2 = args[1].split(' ').map(n => parseInt(n, 10));
  const N = parseInt(args[0], 10); //候補地数
  const T = ary2[0]; //気温求めるパラメータ
  const A = ary2[1]; //理想気温
  const ary = args[2].split(' ').map(n => parseInt(n, 10));
  let min_gap; //理想気温に最も近い気温
  let idx; //敵地番号

  for (let i = 0; i < ary.length; i++) {
    // 理想気温とズレが所持ない時点で最適解なのでブレイク
    if (ary[i] === 0) {
      idx = (i + 1);
      break;
    }
    ave = T - (ary[i] * 0.006); //平均気温
    gap = Math.abs(A - ave);
    if (!min_gap || min_gap > gap) {
      min_gap = gap;
      idx = i + 1; // 帳尻合わせ
    }
  }

  console.log(idx);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
  const args = input.split('\n');
  const ary2 = args[1].split(' ').map(n => parseInt(n, 10));
  const N = parseInt(args[0], 10); //候補地数
  const T = ary2[0]; //気温求めるパラメータ
  const A = ary2[1]; //理想気温
  const ary = args[2].split(' ').map(n => parseInt(n, 10));
  let min_gap; //理想気温に最も近い気温
  let idx; //敵地番号

  for (let i = 0; i < ary.length; i++) {
    ave = T - (ary[i] * 0.006); //平均気温
    gap = Math.abs(A - ave);
    if (!min_gap || min_gap > gap) {
      min_gap = gap;
      idx = i + 1; // 帳尻合わせ
    }
  }

  console.log(idx);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n, t, a := nextInt(), float64(nextInt()), float64(nextInt())
	h := make([]float64, n)

	for i := 0; i < n; i++ {
		h[i] = float64(nextInt())
	}

	nearest := 0
	div := 10000.0
	for i := 0; i < n; i++ {
		temp := t - h[i]*0.006
		if math.Abs(a-temp) < div {
			div = math.Abs(a - temp)
			nearest = i
		}
	}
	fmt.Println(nearest + 1)
}


package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"math"
	"os"
	"reflect"
	"strconv"
	"unsafe"
)

var DEBUG = true

func main() {
	defer Flush()
	N := readi()
	T := readi() * 1000
	A := readi() * 1000

	_, H := readInts(N)

	mi := -1
	md := math.MaxInt32
	for i, v := range H {
		d := abs(T - v*6 - A)
		if d < md {
			md = d
			mi = i
		}
	}
	println(mi + 1)
}

// =============================================================================

// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// these functions are derived from sort in Go source.
// name of functions are changed

// The function panics if the provided interface is not a slice.
func Reverse(slice interface{}) {
	rv := reflect.ValueOf(slice)
	swap := _reverse_Swapper(slice)
	length := rv.Len()
	for i, j := 0, length-1; i < j; i, j = i+1, j-1 {
		swap(i, j)
	}
}

func _reverse_Swapper(slice interface{}) func(i, j int) {
	v := reflect.ValueOf(slice)
	vdata := v.Pointer()
	vlen := v.Len()
	vcap := v.Cap()

	sz := int(v.Type().Elem().Size())

	// for typical small elements
	switch sz {
	case 24: // for slice
		var s [][3]int64
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen
		h.Cap = vcap
		return func(i, j int) { s[i], s[j] = s[j], s[i] }
	case 16: // for string
		var s [][2]int64
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen
		h.Cap = vcap
		return func(i, j int) { s[i], s[j] = s[j], s[i] }
	case 8:
		var s []int64
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen
		h.Cap = vcap
		return func(i, j int) { s[i], s[j] = s[j], s[i] }
	case 4:
		var s []int32
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen
		h.Cap = vcap
		return func(i, j int) { s[i], s[j] = s[j], s[i] }
	case 2:
		var s []int16
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen
		h.Cap = vcap
		return func(i, j int) { s[i], s[j] = s[j], s[i] }
	case 1:
		var s []int8
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen
		h.Cap = vcap
		return func(i, j int) { s[i], s[j] = s[j], s[i] }
	}

	// for large elements
	if sz%16 == 0 {
		m := sz / 16
		var s [][2]int64
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen * m
		h.Cap = vcap * m
		return func(i, j int) {
			for k := 0; k < m; k++ {
				ri := i*m + k
				rj := j*m + k
				s[ri], s[rj] = s[rj], s[ri]
			}
		}
	}
	if sz%8 == 0 {
		m := sz / 8
		var s []int64
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen * m
		h.Cap = vcap * m
		return func(i, j int) {
			for k := 0; k < m; k++ {
				ri := i*m + k
				rj := j*m + k
				s[ri], s[rj] = s[rj], s[ri]
			}
		}
	}
	if sz%4 == 0 {
		m := sz / 4
		var s []int32
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen * m
		h.Cap = vcap * m
		return func(i, j int) {
			for k := 0; k < m; k++ {
				ri := i*m + k
				rj := j*m + k
				s[ri], s[rj] = s[rj], s[ri]
			}
		}
	}
	if sz%2 == 0 {
		m := sz / 2
		var s []int16
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen * m
		h.Cap = vcap * m
		return func(i, j int) {
			for k := 0; k < m; k++ {
				ri := i*m + k
				rj := j*m + k
				s[ri], s[rj] = s[rj], s[ri]
			}
		}
	} else {
		m := sz
		var s []int8
		h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
		h.Data = vdata
		h.Len = vlen * m
		h.Cap = vcap * m
		return func(i, j int) {
			for k := 0; k < m; k++ {
				ri := i*m + k
				rj := j*m + k
				s[ri], s[rj] = s[rj], s[ri]
			}
		}
	}
}

// =============================================================================
// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}


package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	T := getInt()
	A := getInt()
	H := getIntArray(N)

	minDiff := float64(pow(10, 5))
	minIndex := 0
	for i := 0; i < N; i++ {
		t := float64(T) - float64(H[i]) * 0.006
		if math.Abs(float64(A) - t) < minDiff {
			minDiff = math.Abs(float64(A) - t)
			minIndex = i
		}
	}
	fmt.Println(minIndex+1)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func bfs(c int, graph *Graph) {
	next := make([]int, 0)
	next = append(next, c)
	visited := make(map[int]struct{})

	for ; len(next) != 0; {
		u := next[0]
		next = next[1:]
		visited[u] = struct{}{}

		for _, v := range graph.edges[u] {
			_, flag := visited[v]
			if flag {
				continue
			}

			// なにか処理

			next = append(next, v)
		}
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntArray(n int) []int {
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = getInt()
	}
	return array
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return calcMod(n * powMod(n, p-1))
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func makeRange(min, max int) []int {
	a := make([]int, max-min+1)
	for i := range a {
		a[i] = min + i
	}
	return a
}

func powerset2(nums []int) [][]int {
	length := int(math.Pow(2, float64(len(nums))))
	result := make([][]int, length)

	index := 0
	result[index] = []int{}
	index++

	for _, n := range nums {
		max := index
		for i := 0; i < max; i++ {
			result[index] = copyAndAppend(result[i], n)
			index++
		}
	}

	return result
}

func copyAndAppend(nums []int, n int) []int {
	dst := make([]int, len(nums)+1)
	copy(dst, nums)
	dst[len(nums)] = n
	return dst
}

func calcGcd(x, y int) int {
	if y == 0 {
		return x
	} else if x >= y {
		return calcGcd(y, x % y)
	} else {
		return calcGcd(x, y % x)
	}
}

func getDivisor(n int) []int {
	var divisor []int
	divisor = append(divisor, 1)
	if n != 1 {
		divisor = append(divisor, n)
	}

	sqrt := int(math.Sqrt(float64(n)))
	for i := 2; i <= sqrt; i++ {
		if n % i == 0 {
			divisor = append(divisor, i)
			divisor = append(divisor, n/i)
		}
	}
	return divisor
}

type intHeap []int

func (h intHeap) Len() int {
	return len(h)
}

func (h intHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h intHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func initHeap() *intHeap {
	ih := &intHeap{}
	heap.Init(ih)
	return ih
}

func (h *intHeap) pushHeap(n int) {
	heap.Push(h, n)
}

func (h *intHeap) popHeap() int {
	return heap.Pop(h).(int)
}

func factMod(n int) int {
	value := 1
	for ; n > 1; n-- {
		value = calcMod(value * n)
	}
	return value
}

func combinationMod(n, k int) int {
	factN := factMod(n)
	factK := factMod(k)
	factNK := factMod(n - k)
	factKR := powMod(factK, mod - 2)
	factNKR := powMod(factNK, mod - 2)
	return calcMod(factN * calcMod(factKR * factNKR))
}


package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	io, flash := NewIO()
	defer flash()
	n, t, a := io.ScanInt(), io.ScanFloat64(), io.ScanFloat64()
	heights := io.ScanFloat64s(n)

	minDiff := AbsDiffFloat64(t-heights[0]*0.006, a)
	minIdx := 0
	for i, h := range heights[1:] {
		diff := AbsDiffFloat64(t-h*0.006, a)
		if diff < minDiff {
			minDiff = diff
			minIdx = i + 1
		}
	}
	fmt.Println(minIdx + 1)
}

func AbsDiffFloat64(n1, n2 float64) float64 {
	return math.Abs(math.Abs(n1) - math.Abs(n2))
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	io, flash := NewIO()
	defer flash()
	n, t, a := io.ScanInt(), io.ScanFloat64(), io.ScanFloat64()
	heights := io.ScanFloat64s(n)

	minDiff := AbsDiffFloat64(t-heights[0]*0.006, a)
	minIdx := 0
	for i, h := range heights[1:] {
		diff := AbsDiffFloat64(t-h*0.006, a)
		if diff < minDiff {
			minDiff = diff
			minIdx = i+1
		}
	}
	fmt.Println(minIdx + 1)
}

func AbsDiffFloat64(n1, n2 float64) int {
	return int(math.Abs(math.Abs(n1) - math.Abs(n2)))
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc = initScanner(os.Stdin)
	n, t, a := scanInt(sc), scanInt(sc), scanInt(sc)
	h := scanIntSlice(sc, n)
	fmt.Println(solve(t, a, h))
}

func solve(t, a int, h []int) int {
	var point int
	var tmp int

	min := math.MaxInt64
	for i, v := range h {
		tmp = 1000 * a - (1000*t - v*6)
		if min >= int(math.Abs(float64(tmp))) {
			min, point = tmp, i+1
		}
	}

	return point
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanFloat64(sc *bufio.Scanner) float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

func scanFloat64Slice(sc *bufio.Scanner, n int) []float64 {
	fs := make([]float64, n)
	for i := 0; i < n; i++ {
		fs[i] = scanFloat64(sc)
	}

	return fs
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


n = gets.chomp.to_i
t, a = gets.chomp.split.map(&:to_i)
hs = gets.chomp.split.map(&:to_i)

hs.map! { |h| (a - (t - h * 0.006)).abs }
puts hs.index(hs.min) + 1