jiahuimbzuai/CoQuIR huggingface dataset:
//  [java]
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<Integer> one = nextIntArray();
      int X = one.get(0);
      int A = Math.abs(one.get(0) - one.get(1));
      int B = Math.abs(one.get(0) - one.get(2));
      if(A < B){
        myout("B");
      }else{
        myout("A");
      }
      
	}
	//Method addition frame start



	//Method addition frame end
}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int x=scan.nextInt(),a=scan.nextInt(),b=scan.nextInt();
		if(Math.min(a, b)<=x) {
			System.out.println("B");
		}
		else if(Math.min(a, b)>=x) {
			System.out.println("A");
		}

	}

}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int x=scan.nextInt(),a=scan.nextInt(),b=scan.nextInt();
		if(Math.min(a, b)<=x) {
			System.out.println("B");
		}
		else {
			System.out.println("A");
		}

	}

}
//  [cpp]
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);

	if(abs(x-a)<abs(x-b)){
		printf("A\n");
	}else{
		printf("B\n");		
	}


	return 0;
}
//  [cpp]

#include<cmath>
#include <stdio.h>
using namespace std;
int main()
{
int n,a,b;
scanf("%d%d%d",&n,&a,&b);
if (abs(n-a)<abs(n-b))
printf("A");
else
printf("B");
}
//  [cpp]
#include <cstdio>
#include <complex>

int main() {
    int x, a, b;
    scanf("%d %d %d", &x, &a, &b);
    if (std::abs(a - x) > std::abs(b - x))
        puts("B");
    else
        puts("A");
    return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() { 
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int x,a,b;
  cin>>x>>a>>b;
  if(x-a>x-b) cout<<"B"<<endl;
  else cout<<"A"<<endl;

  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main(){
	int x, a, b;
	cin >> x >> a >> b;
	int saa = x-a;
	int sab = x-b;
	if(saa<0) saa=-saa;
	if(sab<0) sab=-sab;
	if(saa>sab) cout << 'A' << endl;
	if(saa<sab) cout << 'B' << endl;
}
//  [cpp]
#include <iostream>
using namespace std;

int main(){
  int x , a , b;
  cin >> x >> a >>b;
  if((x-a) < (x-b)) cout << "A" << endl; 
  else cout << "B" << endl; 
  return 0;
}
//  [c]
#include<stdio.h>

int main()
{
	int x, a, b;
	scanf("%d %d %d", &x, &a, &b);
	if (x > a) {
		a = x - a;
	}
	else {
		a = a - x;
	}
	if (x > b) {
		b = x - b;
	}
	else {
		b = b - x;
	}
	if (a > b) {
		printf("B");
	}
	else {
		printf("A");
	}
	return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>


int main(){
	int a ,b,x;

	scanf("%d%d%d",&x,&a,&b);
	if(abs(x-a)<abs(x-b)) printf("A");
	else printf("B");

	return 0;
}
//  [c]
#include <stdio.h>

int ll(int a){
	if(a<0) a=0-a;
	return a;
}

int main(void){
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);
	if(ll(a-x)<ll(b-x)){printf("A");}else{printf("B");}
	
	return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
int tikai(int a,int b,int c){
  if(abs(b-a)>abs(c-a))
    return 'A';
  else
    return 'B';
}
  int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  printf("%c",tikai(a,b,c));

    
  return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
char tikai(int a,int b,int c){
  char d='A',e='B';
  if(abs(b-a)>abs(c-a))
    return d;
  else
    return e;
}
  int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  printf("%c",tikai(a,b,c));

    
  return 0;
}
//  [c]
#include<stdio.h>
char tikai(int a,int b,int c){
  char d='A',e='B';
  if(abs(b-a)>abs(c-a))
    return d;
  else
    return e;
}
  int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  printf("%c",tikai(a,b,c));

    
  return 0;
}
//  [javascript]
function Main(input) {
  input = input.trim()
  input = input.split(" ").map(Number);
  if(Math.abs(input[0]-input[1])>Math.abs(input[0]-input[2])) console.log("B");
  else console.log("A")
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  const numbers = input.split(' ').map(n => Number(n));
  const x = numbers[0];
  const a = numbers[1];
  const b = numbers[2];

  if (Math.abs(x - a) > Math.abs(x - b)) {
    console.log('B');
  } else {
    console.log('A');
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const x = parseInt(args[0][0], 10)
	const a = parseInt(args[0][1], 10)
	const b = parseInt(args[0][2], 10)
	if (Math.abs(a - x) < Math.abs(b - x)) console.log('A')
	else console.log('B')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
function main(input) {
  input = input.trim();
  const a = input.split(" ").map(Number);
  const b = a[2] - a[0];
  const c = a[1] - a[0];
  if(a[0]>a[1]){
    c = c*(-1);
  }
  if(c<b){
    console.log("A");
  }else{
    console.log("B");
  }
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  input=input.trim();
  const x = parseInt(input.split(" ")[0], 10);
  const a = parseInt(input.split(" ")[1], 10);
  const b = parseInt(input.split(" ")[2], 10);

  if(Math.abs(x-a)>Math.abs(x-b)){
    console.log("B");
  }else{
    console.log("A");
  }

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function main(input) {
  input=input.trim();
  const x = parseInt(input.split(" ")[0], 10);
  const a = parseInt(input.split(" ")[1], 10);
  const b = parseInt(input.split(" ")[2], 10);

  console.log(Math.min.apply(null, [Math.abs(x-a),Math.abs(x-b)]));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import "fmt"

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

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)

	if abs(x-a) < abs(x-b) {
		fmt.Println("A")
	} else {
		fmt.Println("B")
	}
}
//  [go]
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	x, a, b := getInt(), getInt(), getInt()

	if asub(x, a) >= asub(x, b) {
		out("B")
	} else {
		out("A")
	}

}
//  [go]
package main

import (
	"fmt"
	"math"
)

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

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)
	if AbsInt(x, a) < AbsInt(x, b) {
		fmt.Println("A")
	} else {
		fmt.Println("B")
	}
}
//  [go]
package main

import "fmt"

func abs(a int) int {
	if a > 0 {
		return a
	}
	return (-1) * a
}

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)

	if abs(x-a) > abs(x-b) {
		fmt.Println("A")
	} else {
		fmt.Println("B")
	}
}
//  [go]
package main

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

func solution(s string) string {
        var memo [26]int

        for _, r := range s {
                memo[r-'a']++
        }
        for i := range memo {
                if memo[i] == 0 {
                        return string(i + 'a')
                }
        }
        return "None"
}

func main() {
        reader := bufio.NewReaderSize(os.Stdin, 1024)
        str, _, _ := reader.ReadLine()
        fmt.Println(solution(strings.TrimRight(string(str), "\r\n")))
}
//  [go]
package main

import "fmt"

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)
	if x-a > x-b {
		fmt.Println("B")
	} else {
		fmt.Println("A")
	}
}
//  [ruby]
x,a,b = gets.chomp.split.map(&:to_i)

c = (a-x).abs
d = (b-x).abs

if c <= d
  puts "A"
else
  puts "B"
end
//  [ruby]
x, a, b = gets.split.map(&:to_i)
if (x-a).abs - (x-b).abs > 0
  puts "B"
else
  puts "A"
end
//  [ruby]
x,a,b=gets.split(" ").map(&:to_i)

if (a-x).abs<(b-x).abs then
  print("A")
else
  print("B")
end
//  [ruby]
x,a,b = gets.chomp.split(' ').map(&:to_i)
puts [(x-a).abs,(x-b).abs].min
//  [ruby]
# すぬけ君は，数直線上の位置 x に住んでいます． 
# また，位置 a,b にはそれぞれ出前を行っている店 A,B が存在します．
# すぬけ君は，店 A,B のうち，より近いほうから出前をとることにしました． 
# どちらの店がすぬけ君の住んでいる位置により近いかを求めてください．
# ただし，数直線上の 2 点 s,t の間の距離は |s−t| で表されます．

input = gets.chomp.split
x = input[0].to_i
a = input[1].to_i
b = input[2].to_i

(x - a).abs < (x - b).abs ? puts "A" : puts "B"
//  [ruby]
x,a,b = gets.split.map(&:to_i)

if (x - a).abs > (x - b).abs
  puts "a"
else
  puts "b"
end
//  [rust]
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let x = v[0];
	let a = v[1];
	let b = v[2];
	if (a-x).abs() < (b-x).abs() {
		println!("A");
	}else{
		println!("B");
	}
}
//  [rust]
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: i64 = read();
    let a: i64 = read();
    let b: i64 = read();

    if (x - a).abs() > (x - b).abs() {
        println!("B")
    } else {
        println!("A")
    }
}
//  [rust]
fn main(){
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v:Vec<i32> = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
    let mut x = v[0];
    let mut a = v[1];
    let mut b = v[2];

    if (a-x).abs() < (b-x).abs(){
        println!("A");
    }
    else{
        println!("B");
    }
}
//  [rust]
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        (x, a, b): (i32, i32, i32)
    }

    if (x-a).abs()>(x-b).abs() {
        println!("A");
    } else {
        println!("B");
    }
}
//  [rust]
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn is_X(s: &Vec<Vec<(char, u64)>>, i: usize) -> bool{
    return s[0][i].0 == s[1][i].0;
}

fn is_Y(s: &Vec<Vec<(char, u64)>>, i: usize) -> bool{
    return !is_X(s, i);
}

fn main(){
    let n: usize = read_as_vec()[0];

    let mut s: Vec<Vec<(char, u64)>> = Vec::new();

    s.push(read_as_string().chars().zip(vec![0;n].into_iter()).collect::<Vec<(char, u64)>>());
    s.push(read_as_string().chars().zip(vec![0;n].into_iter()).collect::<Vec<(char, u64)>>());

    //init
    let mut i = 0;
    let mut ans: u64;
    let mut is_prev_x: bool;

    if is_X(&s, i){
        ans = 3;
        i += 1;
        is_prev_x = true;
    }else{
        ans = 6;
        i += 2;
        is_prev_x = false;
    }

    while i < n{
        if is_X(&s, i){
            if is_prev_x{
                ans *= 2;
            }else{
                ans *= 1;
            }
            i += 1;
            is_prev_x = true;
        }else{
            if is_prev_x{
                ans *= 2;
            }else{
                ans *= 3;
            }
            i += 2;
            is_prev_x = false;
        }
        ans %= 1_000_000_007;
    }

    println!("{:?}", ans);
}
//  [rust]
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {x:usize, a:usize, b:usize}
    println!("{}", min((x - a).abs(), (x - b).abs()))
}
//  [swift]
let i=readLine()!.characters.split(" ").map{Int(String($0))!};print(abs(i[1]-i[0])<abs(i[2]-i[0]) ?"A":"B")
//  [swift]
import Glibc
extension String: CollectionType {}

var xab = readLine()!.split(" ").map { Int($0)! }
if abs(xab[0] - xab[1]) > abs(xab[0] - xab[2]) {
	print("B")
} else {
  print("A")
}
//  [swift]
//: Playground - noun: a place where people can play


import Foundation
/*
 func readInt(str : String) -> Int{
 return Int(str)  ?? 0
 }
 
 func splitInt(str : String,array :inout [Int]) ->(){
 var temp : String = ""
 for itr in str{
 if itr == " "{
 array.append(Int(temp) ?? 0)
 print(temp)
 temp =  ""
 } else {
 temp += String(itr)
 }
 }
 array.append(Int(temp) ?? 0)
 }
 */

var str: String = readLine() ?? ""
var array :[Int] = []
let startindex = str.startIndex
var temp:String = ""
var index = startindex
for itr in str.characters{
    if itr == " "{
        array.append(Int(temp) ?? 0)
        temp = "";
    } else {
        temp += String(itr);
    }
}
array.append(Int(temp) ?? 0)
if  abs(array[0]-array[1]) < abs(array[0]-array[2]){
    print("A")
}else{
    print("B")
}
//  [swift]
let i=readLine()!.characters.split(" ").map{Int(String($0))!};print((i[1]-i[0])<(i[2]-i[0]) ?"A":"B")
//  [swift]
let i=readLine()!.characters.split(" ").map{Int(String($0))!};print(i[1]-i[0]<i[2]-i[0] ?"A":"B")
//  [swift]
let i=readLine()!.characters.split(" ").map{Int(String($0))!};print(i[1]-i[0]>i[2]-i[0] ?"A":"B")
//  [typescript]
const main = (input) => {
  input = input.split(' ');
  const x = parseInt(input[0], 10);
  const a = parseInt(input[1], 10);
  const b = parseInt(input[2], 10);
  
  if (Math.abs(x-a)>=Math.abs(x-b)) {
    console.log("B");
  }else{
    console.log("A");
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [x, a, b] = stdin.split('\n')[0].split(' ').map(Number)

console.log(Math.abs(x-a) > Math.abs(x-b) ? 'B' : 'A')
//  [typescript]
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let [x,a,b] = t.n(3)
  a-=x;
  b-=x;
  t.o(t.abs(a)<t.abs(b)?'A':'B')
}
main()
//  [typescript]
const main = (input) => {
  input = input.split(' ');
  const a = parseInt(input[0], 10);
  const b = parseInt(input[1], 10);
  
  
  if (a>b) {
    console.log("A");
  }else{
    console.log("B");
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const main = (input) => {
  input = input.split(' ');
  const x = parseInt(input[0], 10);
  const a = parseInt(input[1], 10);
  const b = parseInt(input[2], 10);
  
  if (x-a>=x-b) {
    console.log("B");
  }else{
    console.log("A");
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const main = (input) => {
  input = input.split(' ');
  const x = parseInt(input[0], 10);
  const a = parseInt(input[1], 10);
  const b = parseInt(input[2], 10);
  
  if (x-a>=x-b) {
    console.log("A");
  }else{
    console.log("B");
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
# ABC137D - Summer Vacation
from heapq import heappush, heappushpop


def main():
    N, M, *A = map(int, open(0).read().split())
    # T[i] := candidates of values on i-th deadline
    T = [[] for _ in range(M + 1)]
    for a, b in zip(*[iter(A)] * 2):
        if a <= M:
            T[M - a] += [b]
    q = []  # heapq
    for i in range(M + 1):
        for v in T[i]:
            # keep i worthwhile tasks in i-th day
            if len(q) <= i:
                heappush(q, v)
            else:
                heappushpop(q, v)
    print(sum(q))


if __name__ == "__main__":
    main()
//  [python]
import sys
from heapq import heappop, heappush

input = sys.stdin.readline


def main():
    MAX_A = 10 ** 5
    N, M = map(int, input().split())
    AB = [[] for _ in range(MAX_A + 1)]
    for i in range(N):
        A, B = map(int, input().split())
        AB[A].append(-B)

    p_queue = []
    ans = 0
    for m in range(1, M + 1):
        for b in AB[m]:
            heappush(p_queue, b)
        if p_queue:
            x = heappop(p_queue)
            x *= -1
            ans += x

    print(ans)


if __name__ == "__main__":
    main()
//  [python]
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from heapq import heappush, heappop

    N, M = map(int, input().split())
    AB = [ [] for _ in range(100000) ]

    for _ in range(N):
        a, b = map(int, input().split())
        AB[a-1].append(-b)

    ans = 0
    heap = []
    for a in range(M):
        for b in AB[a]:
            heappush(heap, b)
        if heap:
            ans -= heappop(heap)
    
    print(ans)

main()
//  [python]
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,M = i_map()
    l = [i_list() for _ in range(n)]
    l.sort(reverse = True)

    dp = [0]*(M+1)
    for i,k in l:
        if i > M:
            continue
        m = min(dp[:(-i)])
        d = dp.index(m)
        if k > m:
            dp[d] = k
    print(sum(dp))





if __name__=="__main__":
    main()
//  [python]
import heapq

n,m=map(int,input().split())
mm=10**5+5
c=[[0] for i in range(mm)]

for i in range(n):
  a,b=map(int,input().split())
  c[a].append(b)

#print(c)

ans=0
h=[]
for i in reversed(range(m)):
  d=m-i
  h+=list(map(lambda x:-x, c[d]))
  heapq.heapify(h)
  ans+=-heapq.heappop(h)

print(ans)
//  [python]
import heapq

n,m=map(int,input().split())
mm=10*5+1
c=[[0] for i in range(mm)]

for i in range(n):
  a,b=map(int,input().split())
  c[a].append(b)

#print(c)

ans=0
h=[]
for i in reversed(range(m)):
  d=m-i
  h+=list(map(lambda x:-x, c[d]))+[0]
  heapq.heapify(h)
  ans+=-heapq.heappop(h)

print(ans)
//  [cpp]
//#include<bits/stdc++.h>
#include<cstdio>
#include<queue>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//そっかー

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	int E[100001], H[100001] = {}, n[100001];
	int k = 1;
	rep(i, N) {
		int a = getint();
		E[k] = getint();
		n[k] = H[a];
		H[a] = k++;
	}
	priority_queue<int> que;

	int kotae = 0;
	int j = 0;
	rep1(i, M) {
		for (int j = H[i]; j; j = n[j]) que.push(E[j]);
		if (que.size()) {
			kotae += que.top();
			que.pop();
		}
	}

	printf("%d", kotae);

	Would you please return 0;
}
//  [cpp]
//#include<bits/stdc++.h>
#include<cstdio>
#include<queue>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


void sugoi_sort(int N, int A[], int B[]) {
	const int b = 8;
	int tmpA[100001], tmpB[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) {
			tmpA[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
			tmpB[kazu[A[i] >> k * b & ((1 << b) - 1)]] = B[i];
		}
		k++;
		rep(i, N) kazu2[tmpA[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) {
			A[--kazu2[tmpA[i] >> k * b & ((1 << b) - 1)]] = tmpA[i];
			B[kazu2[tmpA[i] >> k * b & ((1 << b) - 1)]] = tmpB[i];
		}
	}
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	int A[100000], B[100000];
	rep(i, N) {
		A[i] = getint();
		B[i] = getint();
	}
	sugoi_sort(N, A, B);
	priority_queue<int> que;

	int kotae = 0;
	int j = 0;
	rep1(i, M) {
		while (j < N && A[j] <= i) {
			que.push(B[j++]);
		}
		if (que.size()) {
			kotae += que.top();
			que.pop();
		}
	}

	printf("%d", kotae);

	Would you please return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#include <atcoder/segtree>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

P op(P a, P b) { return a.second < b.second ? b : a; }
P e() { return make_pair(-1, -1); }
P target;
bool f(P v) { return v.second < target.second; }

int main() {
    int n, m;
    cin >> n >> m;
    vector<P> p(n);
    rep (i, n) {
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(p.begin(), p.end(), greater<P>());
    //for (auto q : p) cout << "(" << q.first << ", " << q.second << ")" << endl;
    vector<int> l(m+1, -1);
    for (int i = n-1; i >= 0; i--) l[p[i].first] = i;
    //rep (i, m+1) cout << "l[" << i << "]:" << l[i] << endl;
    
    segtree<P, op, e> seg(p);
    int pre = -1;
    ll ans = 0;
    rep (i, m+1) {
        int li = l[i];
        //cout << "i:" << i << endl;
        if (li < 0) {
            if (pre < 0) continue;
            else li = pre;
        }
        //cout << "[" << li << "," << n << "] ";
        target = seg.prod(li, n);
        //cout << " target:" << target.second << " ";
        if (target == e()) continue;
        int id = seg.max_right<f>(li);
        //cout << "id:" << id << endl;
        seg.set(id, e());
        ans += target.second;
        pre = li;
    }
    
    cout << ans << endl;
    
    return 0;
}
//  [c]
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int a[100000];
int s=0;

void push(int x){
	int c=s++, p=(c-1)/2;
	while(c>0 && x>a[p]){
		a[c]=a[p];
		c=p, p=(c-1)/2;
	}
	a[c]=x;
}
int pop(void){
	int t=a[0], x=a[--s];
	int p=0, c=p*2+1;
	while(c<s && a[c=(c+1<s&&a[c+1]>a[c])?c+1:c]>x){
		a[p]=a[c];
		p=c, c=p*2+1;
	}
	a[p]=x;
	return t;
}

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void rsort_u32(void *base, const int count);

uint32_t b[100000][2];
int main(void){
	uint32_t n=nextpint();
	uint32_t m=nextpint();
	for(uint32_t i=0; i<n; i++){
		b[i][0]=nextpint();
		b[i][1]=nextpint();
	}
	rsort_u32(b, n);
	uint32_t ans=0;
	uint32_t p=0;
	for(uint32_t i=1; i<=m; i++){
		for(; p<n&&b[p][0]<=i; p++){
			push(b[p][1]);
		}
		if(s>0) ans+=pop();
	}
	printf("%"PRIu32"\n", ans);
}

void rsort_u32(void *base, const int count){
	uint64_t *a=base;
	uint64_t *b=malloc(count*sizeof(uint64_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}
//  [c]
#include <stdio.h>
#define SIZE 100006
typedef struct mk{
    int b;
    struct mk *next;
}data;
data *input[SIZE],node[SIZE];
int id = 0;
data *New(int b){
    data *tm = &node[id++];
    tm->b = b;
    tm->next = NULL;
    return tm;
}
data *insert(data *root, int b){
    if(root==NULL) return New(b);
    data *tm = New(b);
    tm->next = root;
    return tm;
}
int len = 0,heap[SIZE];
void swap(int *x,int *y){
    int t = *x;
    *x = *y;
    *y = t;
}
int minChild(int *ar,int len,int r,int lf,int rt){
    if(lf<len && ar[r]<ar[lf]) r = lf;
    if(rt<len && ar[r]<ar[rt]) r = rt;
    return r;
}
void heapify(int *ar, int len,int r){
    int c = minChild(ar,len,r,r*2+1,r*2+2);
    if(c!=r){
        swap(&ar[r],&ar[c]);
        heapify(ar,len,c);
    }
}
int getTop(int len){
    int ret = heap[0];
    heap[0] = heap[len];
    heapify(heap,len, 0);
    return ret;
}
void Insert(int v,int len){
    heap[len]=v;
    while(len>0 && heap[(len-1)/2]<heap[len]){
        swap(&heap[len],&heap[(len-1)/2]);
        len = (len-1)/2;
    }
}
void MRoy(){
    int n,m,a,b,length = 0;
    for(int i = 0;i<SIZE;i++) input[i] = NULL;
    scanf("%d%d",&n,&m);
    for(int i = 0;i<n;i++){
        scanf("%d %d",&a,&b);
        input[a] = insert(input[a],b);
    }
    int Ans = 0;
    for(int i = 0;i<m;i++){
        data *tm = input[i+1];
        while(tm!=NULL){
            // printf("%d ",tm->b);
            Insert(tm->b,length);
            length++;
            tm=tm->next;
        }
        if(length){
            Ans += getTop(--length);
        }
            // printf("%d\n",Ans);
    }
    printf("%d\n",Ans);
    return;
}
int main(){
    MRoy();
    return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
long long int a[100005], b[100005];
int asc(const void* x, const void* y)
{
	if (b[*(int*)x] < b[*(int*)y])return 1;
	if (b[*(int*)x] > b[*(int*)y])return -1;
	return 0;
}
int q[100005];
void qq()
{
	int i;
	for (i = 0; i < 100005; i++)
		q[i] = i;
	return;
}
int r(int n)
{
	if (n < 0)
		return -1;
	if (q[n] == n)
		return n;
	if (q[n] < 0)
		return -1;
	return q[n] = r(q[n]);
}
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	long long int i, j;
	for (i = 0; i < n; i++)
		scanf("%lld %lld", &a[i], &b[i]);
	int p[100005];
	for (i = 0; i < m; i++)
		p[i] = 0;
	long long int ans = 0;
	int c[100005];
	for (i = 0; i < n; i++)
		c[i] = i;
	qsort(c, n, sizeof(int), asc);
	qq();

	for (i = 0; i < n; i++)
	{
		j = r(m - a[c[i]]);
		if (j >= 0)
		{
			p[j] = 1;
			q[j]--;
			ans += b[c[i]];
		}
	}
	printf("%lld\n", ans);
	return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[100001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

typedef struct {
	data *obj;
	int size;
} min_heap;

void push(data x, min_heap* h)
{
	int i = h->size;
	data tmp;
	h->obj[(h->size)++] = x;
	while (1) {
		if (i == 0) break;
		else if (h->obj[i].key < h->obj[(i-1)/2].key) {
			tmp = h->obj[(i-1)/2];
			h->obj[(i-1)/2] = h->obj[i];
			h->obj[i] = tmp;
			i = (i - 1) / 2;
		} else break;
	}
}

data pop(min_heap* h)
{
	int i = 0, j;
	data output = h->obj[0], tmp;
	h->obj[0] = h->obj[--(h->size)];
	while (1) {
		if (i * 2 + 1 >= h->size) break;
		else if (i * 2 + 2 >= h->size) j = i * 2 + 1;
		else if (h->obj[i*2+1].key < h->obj[i*2+2].key) j = i * 2 + 1;
		else j = i * 2 + 2;
		if (h->obj[j].key < h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
		} else break;
	}
	return output;
}

int main()
{
	int i, N, M;
	data d[100001];
	scanf("%d %d", &N, &M);
	for (i = 0; i < N; i++) scanf("%d %d", &(d[i].key), &(d[i].id));
	merge_sort(d, N);
	
	int j, ans = 0;
	min_heap h;
	h.size = 0;
	h.obj = (data*)malloc(sizeof(data) * (N + 1));
	for (i = M, j = N - 1; i >= 1; i--) {
		for (; j >= 0 && d[j].key == i; j--) {
			d[j].key += d[j].id;
			d[j].id = d[j].key - d[j].id;
			d[j].key -= d[j].id;
			push(d[j], &h);
		}
		while (h.size > M - i + 1) pop(&h);
	}
	while (h.size > 0) ans += pop(&h).key;
	
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[100001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

typedef struct {
	int *par, *size, *max;
} UF_forest;

void UF_initialize(UF_forest *F, int n)
{
	int i;
	F->par = (int*)malloc(sizeof(int) * (n + 1));
	F->size = (int*)malloc(sizeof(int) * (n + 1));
	F->max = (int*)malloc(sizeof(int) * (n + 1));
	for (i = 1; i <= n; i++) {
		F->par[i] = i;
		F->size[i] = 1;
		F->max[i] = i;
	}
}

void UF_merge(UF_forest *F, int u, int v)
{
	for (; F->par[u] != u; u = F->par[u]);
	for (; F->par[v] != v; v = F->par[v]);
	if (u == v) return;
	else if (F->size[u] > F->size[v]) {
		F->par[v] = u;
		F->size[u] += F->size[v];
		F->max[u] = (F->max[u] < F->max[v])? F->max[v]: F->max[u];
	} else {
		F->par[u] = v;
		F->size[v] += F->size[u];
		F->max[v] = (F->max[u] < F->max[v])? F->max[v]: F->max[u];
	}
}

int UF_root(UF_forest *F, int v)
{
	for (; F->par[v] != v; v = F->par[v]);
	return v;
}

int UF_size(UF_forest *F, int v)
{
	for (; F->par[v] != v; v = F->par[v]);
	return F->size[v];
}

int UF_max(UF_forest *F, int v)
{
	for (; F->par[v] != v; v = F->par[v]);
	return F->max[v];
}

int main()
{
	int i, N, M;
	data d[100001];
	scanf("%d %d", &N, &M);
	for (i = 0; i < N; i++) scanf("%d %d", &(d[i].id), &(d[i].key));
	merge_sort(d, N);
	
	int ans = 0, tmp;
	UF_forest F;
	UF_initialize(&F, M + 1);
	for (i = N - 1; i >= 0; i--) {
		tmp = UF_max(&F, d[i].id);
		if (tmp <= M) {
			ans += d[i].key;
			UF_merge(&F, d[i].id, tmp + 1);
		}
	}
	
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}
//  [javascript]
function main(input) {
    var args = input.trim().split("\n");
    var info = args[0].split(" ").map((v) => parseInt(v));
    var N = info[0];
    var M = info[1];
    var jobs = args.filter((v, i) => i !== 0).map((v) => {
        return v.split(" ").map(v2 => parseInt(v2));
    });

    jobs.sort((a, b) => {
        return a[0] - b[0];
    });


    var pq = new PriorityQueue();
    var result = 0;
    var j = 0;
    for(var i = 1; M >= i; i++) {
        while(!!jobs[j] && jobs[j][0] <= i) {
            pq.push(-jobs[j][1]);
            j++;
        }

        if(pq.size()) result += -pq.pop();
    }

    console.log(result);
}

function PriorityQueue(){
    this.heap = [];
}
PriorityQueue.prototype = {
    push : function(x){
        var h = this.heap, i = h.length++, j;
        while(i){
            j = i-1 >> 1;
            if(h[j] <= x)break;
            h[i] = h[j];
            i = j;
        }
        h[i] = x;
    },
    pop : function(){
        var h = this.heap, r = h[0], x = h.pop();
        var i = 0, k = h.length >> 1, j;
        while (i < k) {
            j = (i << 1) + 1;
            if(h[j+1] < h[j])++j;
            if(x <= h[j])break;
            h[i] = h[j];
            i = j;
        }
        if(h.length)h[i] = x;
        return r;
    },
    size : function(){return this.heap.length;},
    top : function(){return this.heap[0];},
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function PriorityQueue(n){
  this.heap=Array(n||1e5);
  this.size=0;
}
PriorityQueue.prototype = {
  push:function(x){
    var h=this.heap,i=this.size++,j;
    while(i){
      j=i-1>>1;
      if(h[j]<=x)break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
  },
  pop:function(){
    var h=this.heap,s=this.size-1,x=h[s];h[s]=undefined;
    if(s<1)if(s)return;else return --this.size,x;
    var r=h[0],i=0,k=s>>1,j;--this.size;
    while(i<k){
      j=(i<<1)+1;
      if(h[j+1]<h[j])++j;
      if(x<=h[j])break;
      h[i]=h[j],i=j;
    }
    return h[i]=x,r;
  },
  top:function(){return this.heap[0];},
};

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var a = o.m(n);
  a.push([1e9,0]);
  a.sort((a,b)=>a[0]-b[0]);
  var ans = 0, j = 0;
  var pq = new PriorityQueue();
  for(var i = 1; i <= m; i++){
    while(a[j][0] <= i){
      pq.push(-a[j++][1]);
    }
    if(pq.size)ans -= pq.pop();
  }
  return ans;
}
//  [javascript]


function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var M = parseInt(input[0].split(" ")[1]);
  input.shift();
  input.splice(N,input.length);
  var x = input.map(i => i.split(" ").map(i=> parseInt(i)));
  var dp=new Array(Math.pow(10,4)*N+1);
  for(var i=0;i<dp.length;i++){
    if(i==0){
      var sub = new Array(M+1).fill(1);
    }else{
      var sub = new Array(M+1).fill(0);
    }
    dp[i]=sub;
  }
  x.sort(function(a,b){
    if (a[0] < b[0]) return -1;
    if (a[0] > b[0]) return 1;
    if (a[1] < b[1]) return -1;
    if (a[1] > b[1]) return 1;
    return 0;
  })
  dp[0][0]=1;
  for(k=0;k<N;k++){
    for(i=M;i>=1;i--){
      for(j=dp.length-1;j>=0;j--){
        if(dp[j][i-1]==1){
          dp[j][i]=1;
          if(i>=x[k][0]){
            dp[j+x[k][1]][i]=1;
          }
        }
      }
    }
  }
  for(var i=dp.length-1;i>=0;i--){
    if(dp[i][M]==1){
      var ans = i;
      break;
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]


function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var M = parseInt(input[0].split(" ")[1]);
  input.shift();
  input.splice(N,input.length);
  var x = input.map(i => i.split(" ").map(i=> parseInt(i)));
  var dp=new Array(Math.pow(10,5)*N+1);
  for(var i=0;i<dp.length;i++){
    if(i==0){
      var sub = new Array(M+1).fill(1);
    }else{
      var sub = new Array(M+1).fill(0);
    }
    dp[i]=sub;
  }
  x.sort(function(a,b){
    if (a[0] < b[0]) return -1;
    if (a[0] > b[0]) return 1;
    if (a[1] < b[1]) return -1;
    if (a[1] > b[1]) return 1;
    return 0;
  })
  dp[0][0]=1;
  for(k=0;k<N;k++){
    for(i=M;i>=1;i--){
      for(j=dp.length-1;j>=0;j--){
        if(dp[j][i-1]==1){
          dp[j][i]=1;
          if(i>=x[k][0]){
            dp[j+x[k][1]][i]=1;
          }
        }
      }
    }
  }
  for(var i=dp.length-1;i>=0;i--){
    if(dp[i][M]==1){
      var ans = i;
      break;
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

type Job struct {
	a, b int
}

type Jobs []Job

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

type Heap struct {
	size  int
	elems [100000]int
}

type MyHeap interface {
	Size() int
	Push(int)
	Pop() int
}

func (heap *Heap) Size() int {
	return heap.size
}

func (heap *Heap) Push(x int) {
	i := heap.size

	for i > 0 {
		// 親ノードの番号
		p := (i - 1) / 2

		// 逆転していないなら抜ける
		if heap.elems[p] >= x {
			break
		}

		// 親ノードの数字を下ろして、自分は上に
		heap.elems[i] = heap.elems[p]
		i = p
	}

	heap.elems[i] = x
	heap.size++
}

func (heap *Heap) Pop() int {
	// 最小値
	ret := heap.elems[0]
	heap.size--
	// rootに持ってくる値
	x := heap.elems[heap.size]

	// rootから下ろしていく
	i := 0
	for i*2+1 < heap.size {
		// 子同士を比較
		a, b := i*2+1, i*2+2
		if b < heap.size && heap.elems[b] > heap.elems[a] {
			a = b
		}
		if heap.elems[a] <= x {
			break
		}

		// 子の数字を持ち上げる
		heap.elems[i] = heap.elems[a]
		i = a
	}

	heap.elems[i] = x

	return ret
}

func (heap *Heap) Top() int {
	return heap.elems[0]
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	jobs := make(Jobs, n)
	for i := 0; i < n; i++ {
		a, b := nextInt(), nextInt()
		jobs[i] = Job{a, b}
	}
	sort.Sort(jobs)

	ans := 0
	pq := new(Heap)
	for day, id := m-1, 0; day >= 0; day-- {
		for id < n && day+jobs[id].a <= m {
			pq.Push(jobs[id].b)
			id++
		}
		if pq.size > 0 {
			ans += pq.Pop()
		}
	}

	puts(ans)
}
//  [go]
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)
}
//  [go]
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
}