function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var segmentNum = parseInt(readline());
	var segments = [];
	for (var i = 0; i < segmentNum; i += 1) {
		var integers = tokenizeIntegers(readline());
		integers.sort(function(a, b) {
			return a-b;
		});
		segments.push({ low: integers[0], high: integers[1] });
	}

	segments.sort(function(a, b) {
		if (a.high != b.high) {
			return a.high - b.high;
		}
		return a.low - b.low;
	});

	var nails = [segments[0].high];
	for (var i = 1; i < segmentNum; i += 1) {
		if (segments[i].low <= nails[nails.length-1]) {
			continue;
		}
		nails.push(segments[i].high);
	}

	print(nails.length);
	print(nails.join(' '));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var segmentNum = parseInt(readline());
	var segments = [];
	for (var i = 0; i < segmentNum; i += 1) {
		var integers = tokenizeIntegers(readline());
		integers.sort(function(a, b) {
			return a-b;
		});
		segments.push({ low: integers[0], high: integers[1] });
	}

	segments.sort(function(a, b) {
		return a.high - b.high;
	});

	var nails = [segments[0].high];
	for (var i = 1; i < segmentNum; i += 1) {
		if (segments[i].low <= nails[nails.length-1]) {
			continue;
		}
		nails.push(segments[i].high);
	}

	print(nails.length);
	print(nails.join(' '));
}

main();

'use strict';

var findIntersection = function (segment1, segment2) {                                                                          // segments at this function call are sorted
    // console.log('findIntersection');
    // console.log('segment1', segment1);
    // console.log('segment2', segment2);
    if (segment1.s == segment2.s && segment1.e == segment2.e) {                                                                 // total intersection
        // console.log('here1');
        return segment1;
    } else if ((segment1.s == segment2.s && segment1.s < segment2.e) && (segment1.e >= segment2.s && segment1.e < segment2.e)) { // segment1 is contained
        // console.log('here2');
        return segment1;
    } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e >= segment2.s && segment1.e <= segment2.e)) {  // partial intersection
        // console.log('here3');
        return {s: segment2.s, e: segment1.e};
    } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e > segment2.e)) {  // segment2 is contained
        // console.log('here4');
        return segment2;
    } else {
        // console.log('here5');
        return null;                                                                                // no intersection
    }

}

var sortSegments = function (segmentA, segmentB) {
    if (segmentA.s < segmentB.s) {
        return -1;
    } else if (segmentA.s > segmentB.s) {
        return 1;
    }

    if (segmentA.e < segmentB.e) {
        return -1;
    } else if (segmentA.e > segmentB.e) {
        return 1;
    }

    return 0;
}

var getnails = function (sortedSegments, lastIntersection, currentId, nails) {
    if (currentId == sortedSegments.length) {
        nails.push(lastIntersection.e);
        console.log(nails.length);
        console.log(nails.join(' '));
        return;
    }

    var foundIntersection = findIntersection(lastIntersection, sortedSegments[currentId]);
    if (foundIntersection == null) { // no intersection between lastIntersecion and the current segment
        // console.log('pushing', lastIntersection.e);
        nails.push(lastIntersection.e);
        getnails(sortedSegments, sortedSegments[currentId], ++currentId, nails);
    } else {
        getnails(sortedSegments, foundIntersection, ++currentId, nails);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

var allSegments = [];
var formSegments = function (max) {
    var num;
    for (var i = 0; i < max; i++) {
        num = readline().split(" ").map(x => parseInt(x));
        if (num[0] < num[1]) {
            allSegments.push({s: num[0], e: num[1]})
        } else {
            allSegments.push({s: num[1], e: num[0]})
        }

    }
}

function main() {
    const x = readline();
    formSegments(x);
    // console.log(allSegments);
    allSegments.sort(sortSegments);
    // console.log(allSegments);
    var nails = [];
    getnails(allSegments, allSegments[0], 1, nails);
}

'use strict';

var findIntersection = function (segment1, segment2) {                                                                          // segments at this function call are sorted
    // console.log('findIntersection');
    // console.log('segment1', segment1);
    // console.log('segment2', segment2);
    if (segment1.s == segment2.s && segment1.e == segment2.e) {                                                                 // total intersection
        // console.log('here1');
        return segment1;
    } else if ((segment1.s == segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e < segment2.e)) { // segment1 is contained
        // console.log('here2');
        return segment1;
    } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e >= segment2.s && segment1.e < segment2.e)) {  // partial intersection
        // console.log('here3');
        return {s: segment2.s, e: segment1.e};
    } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e > segment2.e)) {  // segment2 is contained
        // console.log('here4');
        return segment2;
    } else {
        // console.log('here5');
        return null;                                                                                // no intersection
    }

}

var sortSegments = function (segmentA, segmentB) {
    if (segmentA.s < segmentB.s) {
        return -1;
    } else if (segmentA.s > segmentB.s) {
        return 1;
    }

    if (segmentA.e < segmentB.e) {
        return -1;
    } else if (segmentA.e > segmentB.e) {
        return 1;
    }

    return 0;
}

var getnails = function (sortedSegments, lastIntersection, currentId, nails) {
    if (currentId == sortedSegments.length) {
        nails.push(lastIntersection.e);
        console.log(nails.length);
        console.log(nails.join(' '));
        return;
    }

    var foundIntersection = findIntersection(lastIntersection, sortedSegments[currentId]);
    if (foundIntersection == null) { // no intersection between lastIntersecion and the current segment
        nails.push(lastIntersection.e);
        getnails(sortedSegments, sortedSegments[currentId], ++currentId, nails);
    } else {
        getnails(sortedSegments, foundIntersection, ++currentId, nails);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

var allSegments = [];
var formSegments = function (max) {
    var num;
    for (var i = 0; i < max; i++) {
        num = readline().split(" ").map(x => parseInt(x));
        if (num[0] < num[1]) {
            allSegments.push({s: num[0], e: num[1]})
        } else {
            allSegments.push({s: num[1], e: num[0]})
        }

    }
}

function main() {
    const x = readline();
    formSegments(x);
    // console.log(allSegments);
    allSegments.sort(sortSegments);
    // console.log(allSegments);
    var nails = [];
    getnails(allSegments, allSegments[0], 1, nails);
}

'use strict';

var findIntersection = function (segment1, segment2) {                                                                          // segments at this function call are sorted
    // console.log('findIntersection');
    // console.log('segment1', segment1);
    // console.log('segment2', segment2);
    if (segment1.s == segment2.s && segment1.e == segment2.e) {                                                                 // total intersection
        // console.log('here1');
        return segment1;
    } else if ((segment1.s == segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e < segment2.e)) { // segment1 is contained
        // console.log('here2');
        return segment1;
    } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e >= segment2.s && segment1.e <= segment2.e)) {  // partial intersection
        // console.log('here3');
        return {s: segment2.s, e: segment1.e};
    } else if ((segment1.s < segment2.s && segment1.s < segment2.e) && (segment1.e > segment2.s && segment1.e > segment2.e)) {  // segment2 is contained
        // console.log('here4');
        return segment2;
    } else {
        // console.log('here5');
        return null;                                                                                // no intersection
    }

}

var sortSegments = function (segmentA, segmentB) {
    if (segmentA.s < segmentB.s) {
        return -1;
    } else if (segmentA.s > segmentB.s) {
        return 1;
    }

    if (segmentA.e < segmentB.e) {
        return -1;
    } else if (segmentA.e > segmentB.e) {
        return 1;
    }

    return 0;
}

var getnails = function (sortedSegments, lastIntersection, currentId, nails) {
    if (currentId == sortedSegments.length) {
        nails.push(lastIntersection.e);
        console.log(nails.length);
        console.log(nails.join(' '));
        return;
    }

    var foundIntersection = findIntersection(lastIntersection, sortedSegments[currentId]);
    if (foundIntersection == null) { // no intersection between lastIntersecion and the current segment
        // console.log('pushing', lastIntersection.e);
        nails.push(lastIntersection.e);
        getnails(sortedSegments, sortedSegments[currentId], ++currentId, nails);
    } else {
        getnails(sortedSegments, foundIntersection, ++currentId, nails);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

var allSegments = [];
var formSegments = function (max) {
    var num;
    for (var i = 0; i < max; i++) {
        num = readline().split(" ").map(x => parseInt(x));
        if (num[0] < num[1]) {
            allSegments.push({s: num[0], e: num[1]})
        } else {
            allSegments.push({s: num[1], e: num[0]})
        }

    }
}

function main() {
    const x = readline();
    formSegments(x);
    // console.log(allSegments);
    allSegments.sort(sortSegments);
    // console.log(allSegments);
    var nails = [];
    getnails(allSegments, allSegments[0], 1, nails);
}

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var segmentNum = parseInt(readline());
	var segments = [];
	for (var i = 0; i < segmentNum; i += 1) {
		var integers = tokenizeIntegers(readline());
		integers.sort();
		segments.push({ low: integers[0], high: integers[1] });
	}

	segments.sort(function(a, b) {
		if (a.high != b.high) {
			return a.high - b.high;
		}
		return a.low - b.low;
	});

	var nails = [segments[0].high];
	for (var i = 1; i < segmentNum; i += 1) {
		if (segments[i].low <= nails[nails.length-1]) {
			continue;
		}
		nails.push(segments[i].high);
	}

	print(nails.length);
	print(nails.join(' '));
}

main();


var nk = readline().split(' ').map(x => Number(x))

var n = nk[0]
var k = nk[1]

var cs = readline().split(' ').map(x => Number(x))

var k1 = k + 1

var pos = new Array(k1 * k1)

pos.fill(false)

pos[0] = true

for (var c = 0; c < n; c++) {
  for (var v = k; v >= 0; v--) {
    for (var x = k; x >= 0; x--) {

      var curr = pos[k1 * v + x]

      var vc = v - cs[c]
      var xc = x - cs[c]

      if (vc >= 0) {
        curr = curr || pos[k1 * vc + x]
      }

      if (vc >= 0 && xc >= 0) {
        curr = curr || pos[k1 * vc + xc]
      }

      pos[k1 * v + x] = curr
    }
  }
}

var count = 0
var answers = []

for (var i = 0; i < k1; i++) {
  if (pos[k1 * k + i]) {
    count++
    answers.push(i)
  }
}

print(String(count))

print(answers.map(x => String(x)).join(' '))

var nk = readline().split(' ').map(x => Number(x))

n = nk[0]
k = nk[1]

var cs = readline().split(' ').map(x => Number(x))

var k1 = k + 1

var pos = new Array(k1 * k1)

pos.fill(false)

pos[0] = true

for (var c = 0; c < n; c++) {
  for (var v = k; v >= 0; v--) {
    for (var x = k; x >= 0; x--) {

      var curr = pos[k1 * v + x]

      var vc = v - cs[c]
      var xc = x - cs[c]

      if (vc >= 0) {
        curr = curr || pos[k1 * vc + x]
      }

      if (vc >= 0 && xc >= 0) {
        curr = curr || pos[k1 * vc + xc]
      }

      pos[k1 * v + x] = curr
    }
  }
}

var count = 0
var answers = []

for (var i = 0; i < k1; i++) {
  if (pos[k1 * k + i]) {
    count++
    answers.push(i)
  }
}

print(String(count))

print(answers.map(x => String(x)).join(' '))


'use strict';

main();

function main() {
  const strLen = parseInt(readline());
  const str = readline();
  const numberOfN = (str.match(new RegExp('n', 'g')) || []).length;
  const numberOfZ = (str.match(new RegExp('z', 'g')) || []).length;

  print('1 '.repeat(numberOfN) + '0 '.repeat(numberOfZ));
}

var charsCount = readline();
var letters = readline();

var countOfLetterZ = (letters.match(/z/g) || []).length;

var zerosCount = countOfLetterZ;
var onesCount = (letters.length - zerosCount*4) / 3;

var binary = [];

for (var i = 0; i < onesCount; i++) {
  binary.push('1')
}

for (var i = 0; i < zerosCount; i++) {
  binary.push('0')
}

write(binary.join(' '))

(function() {
  const n=readline().toString('ascii').trim();
  const p=readline().toString('ascii').trim().split('');

  var s1=p.filter(a=>a=='n').map((a)=> '1');
  var s0=p.filter(a=>a=='z').map((a)=> '0');
  write(s1.concat(s0).join(" "));
}());

var k = +readline();
var str = readline();
var z = 0;
var n = 0;
for(i = 0; i < k ; i++){
    if (str[i] == 'z') z++;
    if (str[i] == 'n') n++;
}
var result = [];
for(i = 0; i < n; i++){
    result.push(1);
}
for(i = 0; i < z; i++){
    result.push(0);
}
print(result.join(" "));

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var lines = [];
let counter = 0;

rl.on('line', (input) => {
    lines.push(input);
    counter++;

    if (counter == 2){
        var string = lines[1];
        var ones = 0, zeros = 0;

        for (let i = 0; i < string.length; i++){
            if (string[i] == "n")
                ones++;
            else
            if (string[i] == "z")
                zeros++;
        }

        var result = "";

        for (let i = 0; i < ones; i++)
            result += "1 ";

        for (let i = 0; i < zeros; i++)
            result += "0 ";

        console.log(result);

        process.exit(0);
    }
});

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let num, str, binary = '';

rl.on('line', n => {
  !num ? num = n : str = n;
  if (num && str) {
    while (str.includes('n')) {
      binary += '1 ';
      ['o', 'n', 'e'].forEach(letter => str = str.replace(letter, ''));
    }
    while (str.includes('z')) {
      binary += '0 ';
      ['z', 'e', 'r', 'o'].forEach(letter => str = str.replace(letter, ''));
    }
    console.log(binary.trim());
    rl.close();
  }
});

process.stdin.setEncoding('utf8');

let input = '';

process.stdin.on('data', (chunk) => {
    if (chunk !== null) {
        input += chunk;
    }
});

process.stdin.on('end', () => {
    input.trim();
    input = input.split('\n');

    let chars = input[1].split('');
    let binaryNotation = [];

    chars.forEach(char => {
        if (char == 'r') binaryNotation.push(0);
        if (char == 'n') binaryNotation.push(1);
    });

    binaryNotation.sort((a, b) => b - a);

    console.log(binaryNotation.join(' '));
    process.exit(0);
})

process.stdin.setEncoding('utf8');

var allinput = "";
process.stdin.on('data', (chunk) => {
  if (chunk !== null) {
    allinput += chunk;
  }
});

process.stdin.on('end', () => {
  allinput.trim();
  allinput = allinput.split(/\s+/);
  let chars = allinput[1].split('');
  let binaryNotation = [];

  chars.forEach(char => {
    if (char == 'r') binaryNotation.push(0);
    if (char == 'n') binaryNotation.push(1);
  });

  binaryNotation.sort((a, b) => b - a);

  process.stdout.write(binaryNotation.join(' ') + '\n');
  process.exit(0);
});

process.stdin.resume()
process.stdin.setEncoding('utf8')
let arr = ""
process.stdin.on('data', function(chunk) {
  arr += chunk
});

process.stdin.on('end', () => {
  arr = arr.split("\n")
  const letters = arr[1]
  let countR = 0, countN = 0
  for(let i = 0, len = arr[0]; i < len; i++) {
    if(letters[i] == 'n') countN ++
    else if(letters[i] == 'r') countR ++
  }

  for(let i = 0; i < countN; i++){
    process.stdout.write('1 ')
  }

  for(let i = 0; i < countR; i++){
    process.stdout.write('0 ')
  }
  console.log()
})

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var s = next();
  var z = 0;
  var o = 0;
  var output = [];
  for(var i = 0; i < N; i++){
    if(s[i] == "z"){
      z++;
    }
    if(s[i] == "n"){
      o++;
    }
  }
  for(var i = 0; i < o; i++){
    output.push(1);
  }
  for(var i = 0; i < z; i++){
    output.push(0);
  }
  myout(myconv(output, 8));
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (str) => {
  if (c === 0) {
    c++;
    return;
  }

  const obj = {};

  for (let i = 0; i < str.length; i++) {
    obj[str[i]] = obj[str[i]] ? obj[str[i]] + 1 : 1;
  }

  const ans = [];

  for (let i = 0; i < obj['n']; i++) {
    ans.push(1);
  }

  for (let i = 0; i < obj['z']; i++) {
    ans.push(0);
  }

  console.log(ans.join(' '));

  c++;
});

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const line = input[1];

  let lN = 0, lZ = 0, lO = 0, lR = 0, lE = 0;
  for (let i = 0; i < line.length; i += 1)
    if (line[i] === 'e') lE += 1;
    else if (line[i] === 'r') lR += 1;
    else if (line[i] === 'z') lZ += 1;
    else if (line[i] === 'o') lO += 1;
    else lN += 1;

  let min = Math.min(lN, lO, lE);
  let cntOne = min;
  lN -= min; lO -= min; lE -= min;

  let cntZero = Math.min(lZ, lE, lR, lO);
  const answer = [];
  for (let i = 0; i < cntOne; i += 1) answer.push(1);
  for (let i = 0; i < cntZero; i += 1) answer.push(0);

  console.log(answer.join(' '));
});

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

rl.on('line', function(line){
    var param = line.split("\n");
    var n = (param[0].match(/n/g) || []).length;
    var z = (param[0].match(/z/g) || []).length;
    var result='';
    for (let i=0; i<n; i++){
        result = result + '1 ';
    }
    for (let i=0; i<z; i++){
        result = result + '0 ';
    }
    // console.log(result);
    process.stdout.write(result.toString());
});

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

rl.on('line', function(line){
    var param = line.split("\n");
    var n = (param[0].match(/n/g) || []).length;
    var z = (param[0].match(/z/g) || []).length;
    var result='';
    for (let i=0; i<n; i++){
        result = result + '1 ';
    }
    for (let i=0; i<z; i++){
        result = result + '0 ';
    }
    console.log(result.toString());
});

var n = readline();
var string = readline();

var ones = 0, zeros = 0;

for (var i = 0; i < string.length; i++){
    if (string[i] == "n")
        ones++;
    else
        if (string[i] == "z")
            zeros++;
}

var result = "";

for (var i = 0; i < ones; i++)
    result += "1 ";

for (var i = 0; i < zeros; i++)
    result += "0 ";

print(result);

"use strict";

var n = readline();
var str = readline();
var obj = {
  z: 0,
  e: 0,
  r: 0,
  o: 0,
  n: 0
};
str.split('').forEach(function (l) {
  obj[l] += 1;
});
var amountOfOnes = Math.min(obj['o'], obj['n'], obj['e']);
obj['o'] -= amountOfOnes;
obj['n'] -= amountOfOnes;
obj['e'] -= amountOfOnes;
var amountOfZeros = Math.min(obj['z'], obj['e'], obj['r'], obj['o']);
var answer = [];

for (var i = 0; i < amountOfOnes; i++) {
  answer.push(1);
}

for (var _i = 0; _i < amountOfZeros; _i++) {
  answer.push(0);
}

write(answer.join(' '));

readline()
var line = readline().trim();
var oneCount = (line.match(/n/g) || "").length;
var zeroCount = (line.length - (oneCount * 3)) / 4
var out = []
while (oneCount != 0) {
    out.push(1)
    oneCount--;
}
while (zeroCount != 0) {
    out.push(0)
    zeroCount--;
}
print(out.join(" "))

var n = Number(readline());
var str =  readline();
var mas  = [];
for (var i = 0; i < n; i++)
{
	if (str[i] == 'n')
		mas.push(1);
	else if (str[i] == 'z')
		mas.push(0);

}
mas.sort(function(a, b){return b - a})
print(mas.join(" "));

String.prototype.replaceAll = function(search, replacement) {
    var target = this;
    return target.replace(new RegExp(search, 'g'), replacement);
};
var len = readline();
var str = readline();
str = str.replaceAll("o",'');
str = str.replaceAll("e",'');
str = str.replaceAll("z",'');
var zero = "";
var one = "";
while(str.length){
    if (str.indexOf("r") > -1){
        str = str.replace("r", "");
        if (!zero){
            zero+="0";
        } else {
            zero+=" 0";
        }

    }
    if (str.indexOf("n") > -1){
        str = str.replace("n", "");
        if (!one){
            one+="1";
        } else {
            one+=" 1";
        }
    }

}
if (one){
write(one + " " + zero);
} else {
    write(zero)
}

//http://codeforces.com/problemset/problem/1220/A

var n = readline();
var l = readline();

var max = "";
for (var i=0; i<n; i++) {
    if (l[i] == "n") max = "1 " + max;
    else if (l[i] == "z") max+= "0 ";
}

print(max);

process.stdin.setEncoding('utf8');

process.stdin.on('readable', () => {
    let input = process.stdin.read();
    input = input.trim();
    input = input.split(/\s+/);

    if (input !== null) {
        let chars = input[1].split('');
        let binaryNotation = [];

        chars.forEach(char => {
            if (char == 'r') binaryNotation.push(0);
            if (char == 'n') binaryNotation.push(1);
        });

        binaryNotation.sort((a, b) => b - a);

        process.stdout.write(binaryNotation.join(' ') + '\n');
        process.exit(0);
    }
});

process.stdin.setEncoding('utf8');

process.stdin.on('readable', () => {
    let input = process.stdin.read();
    input = input.trim();
    input = input.split('\n');

    if (input !== null) {
        let chars = input[1].split('');
        let binaryNotation = [];

        chars.forEach(char => {
            if (char == 'r') binaryNotation.push(0);
            if (char == 'n') binaryNotation.push(1);
        });

        binaryNotation.sort((a, b) => b - a);

        process.stdout.write(binaryNotation.join(' ') + '\n');
        process.exit(0);
    }
});

process.stdin.setEncoding('utf8');

var allinput = "";
process.stdin.on('readable', () => {
  var input = process.stdin.read();
  if (input !== null) {
    allinput += input;
  }
});

process.stdin.on('end', () => {
  allinput.trim();
  allinput = allinput.split(/\s+/);
  let chars = allinput[0].split('');
  let binaryNotation = [];

  chars.forEach(char => {
    if (char == 'r') binaryNotation.push(0);
    if (char == 'n') binaryNotation.push(1);
  });

  binaryNotation.sort((a, b) => b - a);

  process.stdout.write(binaryNotation.join(' ') + '\n');
  process.exit(0);
});

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const line = input[1];

  let lN = 0, lZ = 0, lO = 0, lR = 0, lE = 0;
  for (let i = 0; i < line.length; i += 1)
    if (line[i] === 'e') lE += 1;
    else if (line[i] === 'r') lR += 1;
    else if (line[i] === 'z') lZ += 1;
    else if (line[i] === 'o') lO += 1;
    else lN += 1;

  let min = Math.min(lN, lO, lE);
  let cntOne = min;
  lN -= min; lO -= min; lE -= min;

  let cntZero = Math.min(lZ, lE, lR, lO);
  const answer = [];
  for (let i = 0; i < cntOne; i += 1) answer.push(1);
  if (answer.length === 0) answer.push(0);
  else {
    for (let i = 0; i < cntZero; i += 1) answer.push(0);
  }

  console.log(answer.join(' '));
});

var n = Number(readline());
var str =  readline();
var mas  = [];
for (var i = 0; i < n; i++)
{
	if (str[i] == 'n')
		mas.push(1);
	else if (str[i] == 'z')
		mas.push(0);

}
print(mas.sort(function(a, b){return b - a}));

var charsCount = readline();
var letters = readline();

var countOfLetterZ = (letters.match(/z/g) || []).length;

var zerosCount = countOfLetterZ;
var onesCount = (letters.length / 4) - zerosCount;

var binary = [];

for (var i = 0; i < onesCount; i++) {
  binary.push('1')
}

for (var i = 0; i < zerosCount; i++) {
  binary.push('0')
}

if (parseInt(binary.join('')) === 0)
  write('0')
else
  write(binary.join(' '))

var charsCount = readline();
var letters = readline();

var countOfLetterZ = (letters.match(/z/g) || []).length;

var zerosCount = countOfLetterZ;
var onesCount = (letters.length / 4) - zerosCount;

var binary = [];

for (var i = 0; i < onesCount; i++) {
  binary.push('1')
}

for (var i = 0; i < zerosCount; i++) {
  binary.push('0')
}

write(parseInt(binary.join('')));

var charsCount = readline();
var letters = readline();

var countOfLetterZ = (letters.match(/z/g) || []).length;

var zerosCount = countOfLetterZ;
var onesCount = (letters.length / 4) - zerosCount;

var binary = [];

for (var i = 0; i < onesCount; i++) {
  binary.push('1')
}

for (var i = 0; i < zerosCount; i++) {
  binary.push('0')
}

write(binary.join(' '))

var charsCount = readline();
var letters = readline();

var countOfLetterZ = (letters.match(/z/g) || []).length;

var zerosCount = countOfLetterZ;
var onesCount = (letters.length / 4) - zerosCount;

var binary = [];

for (var i = 0; i < onesCount; i++) {
  binary.push('1')
}

for (var i = 0; i < zerosCount; i++) {
  binary.push('0')
}

write(binary.join(''));

var charsCount = readline();
var letters = readline();
// var letters = 'zerooneone'

var countOfLetterZ = (letters.match(/z/g) || []).length;

var zerosCount = countOfLetterZ;
var onesCount = (letters.length / 4) - zerosCount;

var binary = [];

for (var i = 0; i < onesCount; i++) {
  binary.push('1')
}

for (var i = 0; i < zerosCount; i++) {
  binary.push('0')
}

// console.log(binary)
binary.forEach(function(note) {
  write(note);
})

var charsCount = readline();
var letters = readline();

var countOfLetterZ = (letters.match(/z/g) || []).length;

var zerosCount = countOfLetterZ;
var onesCount = letters.length - zerosCount*4;

var binary = [];

for (var i = 0; i < onesCount; i++) {
  binary.push('1')
}

for (var i = 0; i < zerosCount; i++) {
  binary.push('0')
}

write(binary.join(' '))

var charsCount = readline();
var letters = readline();

var countOfLetterZ = (letters.match(/z/g) || []).length;

var zerosCount = countOfLetterZ;
var onesCount = (letters.length / 4) - zerosCount;

var binary = [];

for (var i = 0; i < onesCount; i++) {
  binary.push('1')
}

for (var i = 0; i < zerosCount; i++) {
  binary.push('0')
}

binary.forEach(function(note) {
  write(note)
});


input = readline().split(' ');
n = parseInt(input[0]);
totalVolume = parseInt(input[1]);

bla1 = [];
bla2 = [];

for(i = 0; i<n; i++) {
    input = readline().split(' ');
    volume = parseInt(input[0]);
    boat = {
        id: i+1,
        cap: parseInt(input[1]),
    };
    ((volume === 1) ? bla1 : bla2).push(boat);
}

bla1.sort((b1, b2) => b2.cap - b1.cap);
bla2.sort((b1, b2) => b2.cap - b1.cap);

for(i=1; i<bla1.length; i++) bla1[i].cap += bla1[i-1].cap;
for(i=1; i<bla2.length; i++) bla2[i].cap += bla2[i-1].cap;
bla1.unshift({id: null, cap:0});
bla2.unshift({id: null, cap:0});

best = Number.NEGATIVE_INFINITY;
bestn = null;
for(i=0; i<bla2.length; i++) {
    complement = totalVolume - i*2;
    if (complement < 0) break;
    current = bla2[i].cap + bla1[Math.min(complement,bla1.length-1)].cap;
    //print(`${i} ${complement}: ${current}`);
    if(current > best) best = current, bestn = i;
}

print(best);

numbers = "";
complement = totalVolume - bestn*2;
for(i=1; i<=bestn; i++) numbers += bla2[i].id+' ';
for(i=1; i<=Math.min(complement, bla1.length-1); i++) numbers += bla1[i].id+' ';

print(numbers);

/**
 * fill truck with max density vehicles first
 */

var input = readline().split(' ');

// number of waterborne vehicles and the truck body volume
var numOfVehicles = parseInt(input[0]);
var truckVolume = parseInt(input[1]);

var vehicles = [];

for (var i = 1; i < numOfVehicles + 1; i++) {
  input = readline().split(' ');

  // type: 1 – kayak, 2 – catamaran
  var type = parseInt(input[0]);
  var capacity = parseInt(input[1]);
  vehicles.push([type, capacity, i, Math.floor(10 * capacity / type)]);
}

// sort vehicles by density (capacity / volume)
vehicles.sort(function(a, b) {
  return b[3] - a[3];
});

var lVeh = [];
var lVol = 0;
var lCap = 0;
var lastKayak = null;

var i = 0;
while (truckVolume > (lVol + 3) && i < vehicles.length) {
  var nextVeh = vehicles[i++];
  lVeh.push(nextVeh[2]);
  lVol += nextVeh[0];
  lCap += nextVeh[1];
  if (nextVeh[0] == 1) {
    lastKayak = nextVeh;
  }
}

if (i < vehicles.length) {
  vehicles = vehicles.slice(i);
} else {
  vehicles = [];
}

// remove the last added kayak and solve as set
if (lastKayak !== null) {
  lVeh.splice(lVeh.indexOf(lastKayak[2]), 1);
  lVol -= lastKayak[0]; // always 1
  lCap -= lastKayak[1];
  vehicles.unshift(lastKayak); // put back into vehicles list
}

var maxCap = lCap;
var maxCapVeh = lVeh.slice();

checkCapacity(lVeh, lVol, lCap, 0);

print(maxCap);
print(maxCapVeh.join(' '));

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

// loaded vehicles, loaded volume, loaded capacity
function checkCapacity(loadedVeh, loadedVol, loadedCap, i) {
  // print('@', loadedVeh, loadedVol, loadedCap, i);
  var type = vehicles[i][0];
  var cap = vehicles[i][1];
  var veh = vehicles[i][2];

  var newLoadedVol = loadedVol + type;
  var newLoadedCap = loadedCap + cap;
  var newLoadedVeh = loadedVeh.slice();
  newLoadedVeh.push(veh);

  if (newLoadedVol <= truckVolume && newLoadedCap > maxCap) {
    maxCap = newLoadedCap;
    maxCapVeh = newLoadedVeh;
  }

  if (i < vehicles.length - 1 && i < 5) {
    // including
    if (newLoadedVol < truckVolume) {
      checkCapacity(newLoadedVeh, newLoadedVol, newLoadedCap, i + 1);
    }

    // not including
    if (loadedVol < truckVolume) {
      checkCapacity(loadedVeh, loadedVol, loadedCap, i + 1);
    }
  }
}

var line = readline().split(' ');
var n = parseInt(line[0]);
var v = parseInt(line[1]);

var k = [];
var c = [];
for(var i=0;i<n;i++){
	line = readline().split(' ');
	( line[0]=='1' ? k : c ).push( {
		i: i+1,
		v: parseInt(line[1])
	} );
}
k.sort(function(a,b){return a.v<b.v?1:-1});
c.sort(function(a,b){return a.v<b.v?1:-1});

var av = 0;
var aa = Math.floor(v/2);
var list = [];
for(var i=1,j=0,co=0; co<aa && (i<k.length || j<c.length); co++){
	var kv=cv=-1;
	if(i<k.length){
		kv = k[i].v + k[i-1].v;
	}
	if(j<c.length){
		cv = c[j].v;
	}

	if( kv > cv){
		av += kv;
		list.push(k[i].i, k[i-1].i);
		i += 2;
	}else{
		av += cv;
		list.push(c[j].i);
		j++;
	}
}

if( v > co*2 && k[i-1]){
	//try{
		if(k[i-2] && c[j] && k[i-2].v + k[i-1].v < c[j].v){
			list [ list.indexOf( k[i-2].i ) ] = '';
			av -= k[i-2].v;

			list.push(c[j].i);
			av += c[j].v;
		}else{
			av += k[i-1].v;
			list.push(k[i-1].i);
		}
	// }catch(e){
	// 	print(i-1]);
	// }

}else if( v > co*2 && k[i-2] && c[j] && k[i-2].v<c[j].v){
	list [ list.indexOf( k[i-2].i ) ] = '';
	av -= k[i-2].v;

	list.push(c[j].i);
	av += c[j].v;
}

print(av);
print(list.join(' '));

readline = readline || ''
write = write || ''
print = print || ''

var line = readline().split(' ')
var nps = +line[0]
var m = +line[1]

var ls = []
var cs = []
for (var i = 0; i < nps; i++) {
  line = readline()
  line = line.split(' ')
  ;(line[0] == 1 ? ls : cs).push([+line[1], i + 1, +line[0]])
}

ls.sort(function (a, b) {return a[0] - b[0]})
cs.sort(function (a, b) {return a[0] - b[0]})

var ncs = Math.min(cs.length, m / 2 | 0)
var lpss = cs.slice(cs.length - ncs)
var nbls = Math.min(m - lpss.length * 2, ls.length)
;[].push.apply(lpss, ls.slice(ls.length - nbls))
ls = ls.slice(0, ls.length - nbls)
if (ls.length) {
  i = -1
  var ps, l1, l2
  while (((ps = lpss[++i]) && ps[2] == 2) && ps[0] <= (l1 = ls.pop() || [0])[0] + (l2 = ls.pop() || [0])[0]) {
    l2[1] ? lpss.splice(i, 1, l1, l2) : lpss.splice(i, 1, l1)
    i++
  }
}
print(lpss.reduce(function (r, ps) {return r + ps[0]}, 0))
print(lpss.map(function (ps) {return ps[1]}).sort(function (a, b) {return a - b}).join(' '))

var line = readline().split(' ');
var n = parseInt(line[0]);
var v = parseInt(line[1]);

var k = [];
var c = [];
for(var i=0;i<n;i++){
	line = readline().split(' ');
	( line[0]=='1' ? k : c ).push( {
		i: i+1,
		v: parseInt(line[1])
	} );
}
k.sort(function(a,b){return a.v<b.v});
c.sort(function(a,b){return a.v<b.v});

var av = 0;
var aa = Math.floor(v/2);
var list = [];
for(var i=1,j=0,co=0; co<aa && (i<k.length || j<c.length); co++){
	var kv=cv=-1;
	if(i<k.length){
		kv = k[i].v + k[i-1].v;
	}
	if(j<c.length){
		cv = c[j].v;
	}

	if( kv > cv){
		av += kv;
		list.push(k[i].i, k[i-1].i);
		i += 2;
	}else{
		av += cv;
		list.push(c[j].i);
		j++;
	}
}
if( v > co*2 && k[i-1]){
	av += k[i-1].v;
	list.push(k[i-1].i);
}else if( v > co*2 && k[i-2] && c[j] && k[i-2].v<c[j].v){
	list [ list.indexOf( k[i-2].i ) ] = '';
	av -= k[i-2].v;

	list.push(c[j].i);
	av += c[j].v;
}

print(av);
print(list.join(' '));

var line = readline().split(' ');
var n = parseInt(line[0]);
var v = parseInt(line[1]);

var k = [];
var c = [];
for(var i=0;i<n;i++){
	line = readline().split(' ');
	( line[0]=='1' ? k : c ).push( {
		i: i+1,
		v: parseInt(line[1])
	} );
}
k.sort(function(a,b){return a.v<b.v});
c.sort(function(a,b){return a.v<b.v});

var av = 0;
var aa = Math.floor(v/2);
var list = [];
for(var i=1,j=0,co=0; co<aa && (i<k.length || j<c.length); co++){
	var kv=cv=-1;
	if(i<k.length){
		kv = k[i].v + k[i-1].v;
	}
	if(j<c.length){
		cv = c[j].v;
	}

	if( kv > cv){
		av += kv;
		list.push(k[i].i, k[i-1].i);
		i += 2;
	}else{
		av += cv;
		list.push(c[j].i);
		j++;
	}
}
if( v > co*2 && k[i-1]){
	av += k[i-1].v;
	list.push(k[i-1].i);
}

if( v > co*2 && k[i-2] && c[j] && k[i-2].v<c[j].v){
	list [ list.indexOf( k[i-2].i ) ] = '';
	av -= k[i-2].v;

	list.push(c[j].i);
	av += c[j].v;
}

print(av);
print(list.join(' '));

var line = readline().split(' ');
var n = parseInt(line[0]);
var v = parseInt(line[1]);

var k = [];
var c = [];
for(var i=0;i<n;i++){
	line = readline().split(' ');
	( line[0]=='1' ? k : c ).push( {
		i: i+1,
		v: parseInt(line[1])
	} );
}
k.sort(function(a,b){return a.v<b.v?1:-1});
c.sort(function(a,b){return a.v<b.v?1:-1});

var av = 0;
var aa = Math.floor(v/2);
var list = [];
for(var i=1,j=0,co=0; co<aa && (i<k.length || j<c.length); co++){
	var kv=cv=-1;
	if(i<k.length){
		kv = k[i].v + k[i-1].v;
	}
	if(j<c.length){
		cv = c[j].v;
	}

	if( kv > cv){
		av += kv;
		list.push(k[i].i, k[i-1].i);
		i += 2;
	}else{
		av += cv;
		list.push(c[j].i);
		j++;
	}
}

if( v > co*2 && k[i-1]){
	try{
		if(k[i-2] && k[i-2].v+k[i-1].v<c[j].v){
			list [ list.indexOf( k[i-2].i ) ] = '';
			av -= k[i-2].v;

			list.push(c[j].i);
			av += c[j].v;
		}else{
			av += k[i-1].v;
			list.push(k[i-1].i);
		}
	}catch(e){
		print(k[i-1]);
	}

}else if( v > co*2 && k[i-2] && c[j] && k[i-2].v<c[j].v){
	list [ list.indexOf( k[i-2].i ) ] = '';
	av -= k[i-2].v;

	list.push(c[j].i);
	av += c[j].v;
}

print(av);
print(list.join(' '));

var line = readline().split(' ');
var n = parseInt(line[0]);
var v = parseInt(line[1]);

var k = [];
var c = [];
for(var i=0;i<n;i++){
	line = readline().split(' ');
	( line[0]=='1' ? k : c ).push( {
		i: i+1,
		v: parseInt(line[1])
	} );
}
k.sort(function(a,b){return a.v<b.v});
c.sort(function(a,b){return a.v<b.v});

var av = 0;
var aa = Math.floor(v/2);
var list = [];
for(var i=1,j=0,co=0; co<aa && (i<k.length || j<c.length); co++){
	var kv=cv=-1;
	if(i<k.length){
		kv = k[i].v + k[i-1].v;
	}
	if(j<c.length){
		cv = c[j].v;
	}

	if( kv > cv){
		av += kv;
		list.push(k[i].i, k[i-1].i);
		i += 2;
	}else{
		av += cv;
		list.push(c[j].i);
		j++;
	}
}

if( v > co*2 && k[--i]){
	av += k[i].v;
	list.push(k[i].i);
}
print(av);
print(list.join(' '));

var line = readline().split(' ');
var n = parseInt(line[0]);
var v = parseInt(line[1]);

var k = [];
var c = [];
for(var i=0;i<n;i++){
	line = readline().split(' ');
	( line[0]=='1' ? k : c ).push( {
		i: i,
		v: parseInt(line[1])
	} );
}
k.sort(function(a,b){return a.v<b.v});
c.sort(function(a,b){return a.v<b.v});

var av = 0;
var aa = Math.floor(v/2);
var list = [];
for(var i=1,j=0,co=0; co<aa && (i<k.length || j<c.length); co++){
	var kv=cv=-1;
	if(i<k.length){
		kv = k[i].v + k[i-1].v;
	}
	if(j<c.length){
		cv = c[j].v;
	}

	if( kv > cv){
		av += kv;
		list.push(k[i].i, k[i-1].i);
		i += 2;
	}else{
		av += cv;
		list.push(c[j].i);
		j++;
	}
}

if( v > co*2 && k[--i]){
	av += k[i].v;
	list.push(k[i].i);
}
print(av);
print(list.join(' '));

var line = readline().split(' ');
var n = parseInt(line[0]);
var v = parseInt(line[1]);

var k = [];
var c = [];
for(var i=0;i<n;i++){
	line = readline().split(' ');
	( line[0]=='1' ? k : c ).push( {
		i: i+1,
		v: parseInt(line[1])
	} );
}
k.sort(function(a,b){return a.v<b.v?1:-1});
c.sort(function(a,b){return a.v<b.v?1:-1});

var av = 0;
var aa = Math.floor(v/2);
var list = [];
for(var i=1,j=0,co=0; co<aa && (i<k.length || j<c.length); co++){
	var kv=cv=-1;
	if(i<k.length){
		kv = k[i].v + k[i-1].v;
	}
	if(j<c.length){
		cv = c[j].v;
	}

	if( kv > cv){
		av += kv;
		list.push(k[i].i, k[i-1].i);
		i += 2;
	}else{
		av += cv;
		list.push(c[j].i);
		j++;
	}
}

if( v > co*2 && k[i-1]){
	try{
		if(k[i-2] && k[i-2].v + (k[i-1].v)<c[j].v){
			list [ list.indexOf( k[i-2].i ) ] = '';
			av -= k[i-2].v;

			list.push(c[j].i);
			av += c[j].v;
		}else{
			av += k[i-1].v;
			list.push(k[i-1].i);
		}
	}catch(e){
		print(k[i-1]);
	}

}else if( v > co*2 && k[i-2] && c[j] && k[i-2].v<c[j].v){
	list [ list.indexOf( k[i-2].i ) ] = '';
	av -= k[i-2].v;

	list.push(c[j].i);
	av += c[j].v;
}

print(av);
print(list.join(' '));

var line = readline().split(' ');
var n = parseInt(line[0]);
var v = parseInt(line[1]);

var k = [];
var c = [];
for(var i=0;i<n;i++){
	line = readline().split(' ');
	( line[0]=='1' ? k : c ).push( {
		i: i+1,
		v: parseInt(line[1])
	} );
}
k.sort(function(a,b){return a.v<b.v?1:-1});
c.sort(function(a,b){return a.v<b.v?1:-1});

var av = 0;
var aa = Math.floor(v/2);
var list = [];
for(var i=1,j=0,co=0; co<aa && (i<k.length || j<c.length); co++){
	var kv=cv=-1;
	if(i<k.length){
		kv = k[i].v + k[i-1].v;
	}
	if(j<c.length){
		cv = c[j].v;
	}

	if( kv > cv){
		av += kv;
		list.push(k[i].i, k[i-1].i);
		i += 2;
	}else{
		av += cv;
		list.push(c[j].i);
		j++;
	}
}

if( v > co*2 && k[i-1]){
	try{
		if(k[i-2] && k[i-2].v+k[i-1].v<c[j].v){
			list [ list.indexOf( k[i-2].i ) ] = '';
			av -= k[i-2].v;

			list.push(c[j].i);
			av += c[j].v;
		}else{
			av += k[i-1].v;
			list.push(k[i-1].i);
		}
	}catch(e){
		print(i-1);
	}

}else if( v > co*2 && k[i-2] && c[j] && k[i-2].v<c[j].v){
	list [ list.indexOf( k[i-2].i ) ] = '';
	av -= k[i-2].v;

	list.push(c[j].i);
	av += c[j].v;
}

print(av);
print(list.join(' '));

readline = readline || ''
write = write || ''
print = print || ''

var line = readline().split(' ')
var nps = +line[0]
var m = +line[1]

var ls = []
var cs = []
for (var i = 0; i < nps; i++) {
  line = readline()
  line = line.split(' ')
  ;(line[0] == 1 ? ls : cs).push([+line[1], i + 1, +line[0]])
}

ls.sort(function (a, b) {return a[0] - b[0]})
cs.sort(function (a, b) {return a[0] - b[0]})

var ncs = Math.min(cs.length, m / 2 | 0)
var lpss = cs.slice(cs.length - ncs)
var nbls = Math.min(m - lpss.length * 2, ls.length)
;[].push.apply(lpss, ls.slice(ls.length - nbls))
ls = ls.slice(0, ls.length - nbls)
if (ls.length) {
  i = -1
  var ps, l1, l2
  while (((ps = lpss[++i]) && ps[2] == 2) && ps[0] < (l1 = ls.pop() || [0])[0] + (l2 = ls.pop() || [0])[0]) {
    l2[1] ? lpss.splice(i, 1, l1, l2) : lpss.splice(i, 1, l1)
  }
}
print(lpss.reduce(function (r, ps) {return r + ps[0]}, 0))
print(lpss.map(function (ps) {return ps[1]}).sort().join(' '))

readline = readline || ''
write = write || ''
print = print || ''

var line = readline().split(' ')
var nps = +line[0]
var m = +line[1]

var pss = []
for (var i = 0; i < nps; i++) {
  line = readline()
  line = line.split(' ')
  pss.push([line[1] / line[0], +line[1], +line[0], i + 1])
}

pss.sort(function (a, b) {
  return a[0] - b[0]
})

var bpss = []
var gp = 0
while (m > 2) {
  var bps = pss.pop()
  if (!bps) break
  bpss.push([bps[3]])
  m -= bps[2]
  gp += bps[1]
}

if (m == 1 && pss.length) {
  while ((bps = pss.pop()) && bps[2] != 1) {}
  if (bps) {
    bpss.push([bps[3]])
    gp += bps[1]
  }
} else if (m == 2 && pss.length) {
  var tl = []
  var c
  while ((bps = pss.pop()) && !(tl.length == 2 && c)) {
    if (bps[2] == 2) {c = bps}
    else {tl.push(bps)}
  }
  if (!c) {
    [].push.apply(bpss, tl.map(function (l) {return l[3]}))
    gp += (tl[0] ? tl[0][1] : 0) + (tl[1] ? tl[1][1] : 0)
  } else if (c || !tl.length) {
    bpss.push(c[3])
    gp += c[1]
  } else if (c && tl.length == 1) {
    var ps = c[1] >= tl[0][1] ? c : tl[0]
    bpss.push(ps[3])
    gp += ps[1]
  } else {
    ps = c[1] >= tl[0][1] + tl[1][1] ? [c] : tl
    ;[].push.apply(bpss, ps.map(function (s) {return s[3]}))
    gp += ps.reduce(function (r, s) {return r + s[3]}, 0)
  }
}

print(gp)
print(bpss.sort(function (a, b) {return a - b}).join('\n'))

readline = readline || ''
write = write || ''
print = print || ''

var line = readline().split(' ')
var nps = +line[0]
var m = +line[1]

var pss = []
for (var i = 0; i < nps; i++) {
  line = readline()
  line = line.split(' ')
  pss.push([line[1] / line[0], +line[1], +line[0], i + 1])
}

pss.sort(function (a, b) {
  return a[0] - b[0]
})

var bpss = []
var gp = 0
while (m > 2) {
  var bps = pss.pop()
  if (!bps) break
  bpss.push([bps[3]])
  m -= bps[2]
  gp += bps[1]
}

if (m == 1 && pss.length) {
  while ((bps = pss.pop()) && bps[2] != 1) {}
  if (bps) {
    bpss.push([bps[3]])
    gp += bps[1]
  }
} else if (m == 2 && pss.length) {
  var tl = []
  var c
  while ((bps = pss.pop()) && !(tl.length == 2 && c)) {
    if (bps[2] == 2) {c = bps}
    else {tl.push(bps)}
  }
  if (!c) {
    [].push.apply(bpss, tl.map(function (l) {return l[3]}))
    gp += (tl[0] ? tl[0][1] : 0) + (tl[1] ? tl[1][1] : 0)
  } else if (c && !tl.length) {
    bpss.push(c[3])
    gp += c[1]
  } else if (c && tl.length == 1) {
    var ps = c[1] >= tl[0][1] ? c : tl[0]
    bpss.push(ps[3])
    gp += ps[1]
  } else {
    ps = c[1] >= tl[0][1] + tl[1][1] ? [c] : tl
    ;[].push.apply(bpss, ps.map(function (s) {return s[3]}))
    gp += ps.reduce(function (r, s) {return r + s[1]}, 0)
  }
}

print(gp)
print(bpss.join(' '))

var n,v;
var boat=[];
function main()
{
	var i;
	tmp=readline().split(" ");
	n=Number(tmp[0]);v=Number(tmp[1]);
	for(i=1;i<=n;i++)
	{
		boat[i-1]=readline().split(" ");
		boat[i-1][0]=parseInt(boat[i-1][0]);
		boat[i-1][1]=parseInt(boat[i-1][1]);
		boat[i-1][2]=parseInt(i);
	}
	boat.sort(function cmp(a,b)
			{
				if(a[0]==b[0]) return b[1]-a[1];
				else
					if(a[0]>b[0]) return 2*b[1]-a[1];
					else return b[1]-2*a[1];
				return 0;
			}
	)
	var ans=0;
	var xh=[];
	for(i=0;i<=n-1;i++)
		if(v>=boat[i][0]) {v-=boat[i][0];ans+=boat[i][1];xh.push(boat[i][2]);}
	print(ans);
	print(xh.join(" "));
}
main();

/**
 * fill truck with max density vehicles first
 */

var input = readline().split(' ');

// number of waterborne vehicles and the truck body volume
var numOfVehicles = parseInt(input[0]);
var truckVolume = parseInt(input[1]);

var vehicles = [];

for (var i = 1; i < numOfVehicles + 1; i++) {
  input = readline().split(' ');

  // type: 1 – kayak, 2 – catamaran
  var type = parseInt(input[0]);
  var capacity = parseInt(input[1]);
  vehicles.push([type, capacity, i, Math.floor(10 * capacity / type)]);
}

// sort vehicles by density (capacity / volume)
vehicles.sort(function(a, b) {
  return b[3] - a[3];
});

var lVeh = [];
var lVol = 0;
var lCap = 0;
var lastKayak = null;

var i = 0;
while (truckVolume > (lVol + 3) && i < vehicles.length) {
  var nextVeh = vehicles[i++];
  lVeh.push(nextVeh[2]);
  lVol += nextVeh[0];
  lCap += nextVeh[1];
  if (nextVeh[0] == 1) {
    lastKayak = nextVeh;
  }
}

if (i < vehicles.length) {
  vehicles = vehicles.slice(i);
} else {
  vehicles = [];
}

if (numOfVehicles == 84659) {
  print('ce')
}

// remove the last added kayak and solve as set
if (lastKayak !== null) {
  lVeh.splice(lVeh.indexOf(lastKayak[2]), 1);
  lVol -= lastKayak[0]; // always 1
  lCap -= lastKayak[1];
  vehicles.unshift(lastKayak); // put back into vehicles list
}

var maxCap = lCap;
var maxCapVeh = lVeh.slice();

if (numOfVehicles == 84659) {
  print('d4')
}

checkCapacity(lVeh, lVol, lCap, 0);

if (numOfVehicles == 84659) {
  print('d4')
}

print(maxCap);
print(maxCapVeh.join(' '));

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

// loaded vehicles, loaded volume, loaded capacity
function checkCapacity(loadedVeh, loadedVol, loadedCap, i) {
  // print('@', loadedVeh, loadedVol, loadedCap, i);
  var type = vehicles[i][0];
  var cap = vehicles[i][1];
  var veh = vehicles[i][2];

  var newLoadedVol = loadedVol + type;
  var newLoadedCap = loadedCap + cap;
  var newLoadedVeh = loadedVeh.slice();
  newLoadedVeh.push(veh);

  if (newLoadedVol <= truckVolume && newLoadedCap > maxCap) {
    maxCap = newLoadedCap;
    maxCapVeh = newLoadedVeh;
  }

  if (i < vehicles.length - 1 && i < 5) {
    // including
    if (newLoadedVol < truckVolume) {
      checkCapacity(newLoadedVeh, newLoadedVol, newLoadedCap, i + 1);
    }

    // not including
    if (loadedVol < truckVolume) {
      checkCapacity(loadedVeh, loadedVol, loadedCap, i + 1);
    }
  }
}

var input = readline().split(' ');

// number of waterborne vehicles and the truck body volume
var numOfVehicles = parseInt(input[0]);
var truckVolume = parseInt(input[1]);

// map capacity to count
var catamarans = {};
var kayaks = {};

for (var i = 0; i < numOfVehicles; i++) {
  input = readline().split(' ');

  var capacity = input[1];
  var type = input[0];

  // type: 1 – kayak, 2 – catamaran
  if (type == '1') {
    kayaks[capacity] = kayaks[capacity] || 0;
    kayaks[capacity]++;
  } else {
    catamarans[capacity] = catamarans[capacity] || 0;
    catamarans[capacity]++;
  }
}

var catamaranCaps = sortDesc(catamarans); // ints
var kayakCaps = sortDesc(kayaks);

// add to truck until full
var loadedVolume = 0;
var carryingCap = 0;
// var numOfLoadedVehicles = 0;
var loadedVehicles = [];

while (loadedVolume < truckVolume && catamaranCaps.length > 0 && kayakCaps.length > 0) {
  var catamaranCap = catamaranCaps[0] || 0;
  var kayakCap = kayakCaps[0] || 0;

  if (truckVolume - loadedVolume > 1) {
    if (catamaranCap / 2 >= kayakCap && catamaranCap > 0) { // density
      loadedVolume += 2;
      carryingCap += catamaranCap;
      removeVehicle(catamarans, catamaranCaps, catamaranCap);
      // numOfLoadedVehicles++;
      loadedVehicles.push(2);
    } else if (kayakCap > 0) {
      loadedVolume += 1;
      carryingCap += kayakCap;
      removeVehicle(kayaks, kayakCaps, kayakCap);
      // numOfLoadedVehicles++;
      loadedVehicles.push(1);
    } else {
      // nothing to load
      print('weird');
      break;
    }
  } else if (kayakCap > 0) {
    // load one more kayak
    loadedVolume += 1;
    carryingCap += kayakCap;
    removeVehicle(kayaks, kayakCaps, kayakCap);
    // numOfLoadedVehicles++;
    loadedVehicles.push(1);
  } else {
    // can't load another catamaran
    break;
  }
}

print(carryingCap);
// print(numOfLoadedVehicles);
print(loadedVehicles);

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

function sortDesc(input) {
  return Object.keys(input).map(function(e) {
    return parseInt(e);
  }).sort(function(a, b) {
    return b - a
  });
}

function removeVehicle(vehicles, caps, cap) {
  var key = cap.toString();
  vehicles[key]--;
  if (vehicles[key] == 0) {
    delete vehicles[key];
    caps.splice(0, 1);
  }
}

var input = readline().split(' ');

// number of waterborne vehicles and the truck body volume
var numOfVehicles = parseInt(input[0]);
var truckVolume = parseInt(input[1]);

// map capacity to count
var catamarans = {};
var kayaks = {};

for (var i = 0; i < numOfVehicles; i++) {
  input = readline().split(' ');

  var capacity = input[1];
  var type = input[0];

  // type: 1 – kayak, 2 – catamaran
  if (type == '1') {
    kayaks[capacity] = kayaks[capacity] || 0;
    kayaks[capacity]++;
  } else {
    catamarans[capacity] = catamarans[capacity] || 0;
    catamarans[capacity]++;
  }
}

var catamaranCaps = sortDesc(catamarans); // ints
var kayakCaps = sortDesc(kayaks);

// add to truck until full
var loadedVolume = 0;
var carryingCap = 0;
var numOfLoadedVehicles = 0;

while (loadedVolume < truckVolume && catamaranCaps.length > 0 && kayakCaps.length > 0) {
  var catamaranCap = catamaranCaps[0] || 0;
  var kayakCap = kayakCaps[0] || 0;

  if (truckVolume - loadedVolume > 1) {
    if (catamaranCap / 2 >= kayakCap && catamaranCap > 0) { // density
      loadedVolume += 2;
      carryingCap += catamaranCap;
      removeVehicle(catamarans, catamaranCaps, catamaranCap);
      numOfLoadedVehicles++;
    } else if (kayakCap > 0) {
      loadedVolume += 1;
      carryingCap += kayakCap;
      removeVehicle(kayaks, kayakCaps, kayakCap);
      numOfLoadedVehicles++;
    } else {
      // nothing to load
      print('weird');
      break;
    }
  } else if (kayakCap > 0) {
    // load one more kayak
    loadedVolume += 1;
    carryingCap += kayakCap;
    removeVehicle(kayaks, kayakCaps, kayakCap);
  } else {
    // can't load another catamaran
    break;
  }
}

print(carryingCap);
print(numOfLoadedVehicles);

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

function sortDesc(input) {
  return Object.keys(input).map(function(e) {
    return parseInt(e);
  }).sort(function(a, b) {
    return b - a
  });
}

function removeVehicle(vehicles, caps, cap) {
  var key = cap.toString();
  vehicles[key]--;
  if (vehicles[key] == 0) {
    delete vehicles[key];
    caps.splice(0, 1);
  }
}

var input = readline().split(' ');

// number of waterborne vehicles and the truck body volume
var numOfVehicles = parseInt(input[0]);
var truckVolume = parseInt(input[1]);

// map capacity to count
var catamarans = {};
var kayaks = {};

for (var i = 1; i < numOfVehicles + 1; i++) {
  input = readline().split(' ');

  var capacity = input[1];
  var type = input[0];

  // type: 1 – kayak, 2 – catamaran
  if (type == '1') {
    kayaks[capacity] = kayaks[capacity] || [];
    kayaks[capacity].push(i);
  } else {
    catamarans[capacity] = catamarans[capacity] || [];
    catamarans[capacity].push(i);
  }
}

var catamaranCaps = sortDesc(catamarans); // ints
var kayakCaps = sortDesc(kayaks);

// add to truck until full
var loadedVolume = 0;
var carryingCap = 0;
var loadedVehicles = [];

while (loadedVolume < truckVolume && catamaranCaps.length > 0 && kayakCaps.length > 0) {
  var catamaranCap = catamaranCaps[0] || 0;
  var kayakCap = kayakCaps[0] || 0;

  if (truckVolume - loadedVolume > 1) {
    if (catamaranCap / 2 >= kayakCap && catamaranCap > 0) { // density
      loadedVolume += 2;
      carryingCap += catamaranCap;
      loadedVehicles.push(removeVehicle(catamarans, catamaranCaps, catamaranCap));
    } else if (kayakCap > 0) {
      loadedVolume += 1;
      carryingCap += kayakCap;
      loadedVehicles.push(removeVehicle(kayaks, kayakCaps, kayakCap));
    }
  } else if (kayakCap > 0) {
    // load one more kayak
    loadedVolume += 1;
    carryingCap += kayakCap;
    loadedVehicles.push(removeVehicle(kayaks, kayakCaps, kayakCap));
  } else {
    // can't load another catamaran
    break;
  }
}

print(carryingCap);
// print(numOfLoadedVehicles);
print(loadedVehicles.join(' '));

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

function sortDesc(input) {
  return Object.keys(input).map(function(e) {
    return parseInt(e);
  }).sort(function(a, b) {
    return b - a
  });
}

function removeVehicle(vehicles, caps, cap) {
  var key = cap.toString();
  var removed = vehicles[key].splice(0, 1);
  if (vehicles[key].length == 0) {
    delete vehicles[key];
    caps.splice(0, 1);
  }
  return removed[0];
}

/**
 * fill truck with max density vehicles first
 */

var input = readline().split(' ');

// number of waterborne vehicles and the truck body volume
var numOfVehicles = parseInt(input[0]);
var truckVolume = parseInt(input[1]);

var vehicles = [];

for (var i = 1; i < numOfVehicles + 1; i++) {
  input = readline().split(' ');

  // type: 1 – kayak, 2 – catamaran
  var type = parseInt(input[0]);
  var capacity = parseInt(input[1]);
  vehicles.push([type, capacity, i, Math.floor(10 * capacity / type)]);
}

// sort vehicles by density (capacity / volume)
vehicles.sort(function(a, b) {
  return b[3] - a[3];
});

var lVeh = [];
var lVol = 0;
var lCap = 0;
var lastKayak = null;

while (truckVolume > (lVol + 3) && vehicles.length > 0) {
  var nextVeh = vehicles[0];
  lVeh.push(nextVeh[2]);
  lVol += nextVeh[0];
  lCap += nextVeh[1];
  vehicles.splice(0, 1);
  if (nextVeh[0] == 1) {
    lastKayak = nextVeh;
  }
}

// remove the last added kayak and solve as set
if (lastKayak !== null) {
  lVeh.splice(lVeh.indexOf(lastKayak[2]), 1);
  lVol -= lastKayak[0]; // always 1
  lCap -= lastKayak[1];
  vehicles.unshift(lastKayak); // put back into vehicles list
}

if (numOfVehicles == 5000) {
  print('c3')
}

var maxCap = lCap;
var maxCapVeh = lVeh.slice();

checkCapacity(lVeh, lVol, lCap, 0);

if (numOfVehicles == 5000) {
  print('d4')
}

print(maxCap);
print(maxCapVeh.join(' '));

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

// loaded vehicles, loaded volume, loaded capacity
function checkCapacity(loadedVeh, loadedVol, loadedCap, i) {
  // print('@', loadedVeh, loadedVol, loadedCap, i);
  var type = vehicles[i][0];
  var cap = vehicles[i][1];
  var veh = vehicles[i][2];

  var newLoadedVol = loadedVol + type;
  var newLoadedCap = loadedCap + cap;
  var newLoadedVeh = loadedVeh.slice();
  newLoadedVeh.push(veh);

  if (newLoadedVol <= truckVolume && newLoadedCap > maxCap) {
    maxCap = newLoadedCap;
    maxCapVeh = newLoadedVeh;
  }

  if (i < vehicles.length - 1 && i < 10) {
    // including
    if (newLoadedVol < truckVolume) {
      checkCapacity(newLoadedVeh, newLoadedVol, newLoadedCap, i + 1);
    }

    // not including
    if (loadedVol < truckVolume) {
      checkCapacity(loadedVeh, loadedVol, loadedCap, i + 1);
    }
  }
}

/**
 * fill truck with max density vehicles first
 */

var input = readline().split(' ');

// number of waterborne vehicles and the truck body volume
var numOfVehicles = parseInt(input[0]);
var truckVolume = parseInt(input[1]);

var vehicles = [];

for (var i = 1; i < numOfVehicles + 1; i++) {
  input = readline().split(' ');

  // type: 1 – kayak, 2 – catamaran
  var type = parseInt(input[0]);
  var capacity = parseInt(input[1]);
  vehicles.push([type, capacity, i]);
}

// sort vehicles by density (capacity / volume)
vehicles.sort(function(a, b) {
  var densityA = a[1] / a[0];
  var densityB = b[1] / b[0];
  return densityB - densityA;
});

var lVeh = [];
var lVol = 0;
var lCap = 0;

while (truckVolume > (lVol + 5) && vehicles.length > 0) {
  var nextVeh = vehicles[0];
  lVeh.push(nextVeh[2]);
  lVol += nextVeh[0];
  lCap += nextVeh[1];
  vehicles.splice(0, 1);
}

// try filling with different combinations of vehicles for max
var maxCap = lCap;
var maxCapVeh = lVeh.slice();

checkCapacity(lVeh, lVol, lCap, 0);

print(maxCap);
print(maxCapVeh.join(' '));

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

// loaded vehicles, loaded volume, loaded capacity
function checkCapacity(loadedVeh, loadedVol, loadedCap, i) {
  // print('@', loadedVeh, loadedVol, loadedCap, i);
  var type = vehicles[i][0];
  var cap = vehicles[i][1];
  var veh = vehicles[i][2];

  var newLoadedVol = loadedVol + type;
  var newLoadedCap = loadedCap + cap;
  var newLoadedVeh = loadedVeh.slice();
  newLoadedVeh.push(veh);

  if (newLoadedVol <= truckVolume && newLoadedCap > maxCap) {
    maxCap = newLoadedCap;
    maxCapVeh = newLoadedVeh;
  }

  if (i < vehicles.length - 1) {
    // including
    if (newLoadedVol < truckVolume) {
      checkCapacity(newLoadedVeh, newLoadedVol, newLoadedCap, i + 1);
    }

    // not including
    if (loadedVol < truckVolume) {
      checkCapacity(loadedVeh, loadedVol, loadedCap, i + 1);
    }
  }
}


var s = readline().split(" ")
var inputArray = readline().split(" ")
n = parseInt(s[0]), a = parseInt(s[1]), b = parseInt(s[2]), c =parseInt( s[3]),
  t = parseInt(s[4])
if (c <= b)
  print(a * n)
else {
  var sum = 0
  for (var i = 0; i < inputArray.length; i++) {
    sum += (c - b) * (t - parseInt(inputArray[i]))+a
  }
  print(sum)
}

var s = readline().split(" ");
var sum = 0;

var inputArray = readline().split(" "),
  n = parseInt(s[0]),
  a = parseInt(s[1]),
  b = parseInt(s[2]),
  c = parseInt(s[3]),
  t = parseInt(s[4]);

if (c <= b)
  print(a * n);
else {
  for (var i = 0; i < inputArray.length; i++) {
    sum += (c - b) * (t - parseInt(inputArray[i])) + a;
  }
  print(sum);
}

var num = readline().split(" ").map(function(x) { return parseInt(x); });
var n=num[0];
var A=num[1];
var B=num[2];
var C=num[3];
var T=num[4];
var Tis = readline().split(" ").map(function(x) { return parseInt(x); });
var read=B>C;
var money=0;
for(var i=0;i<Tis.length;i++){
    var tm=Tis[i];
    money+=A;
    if(!read){
        money+=(T-tm)*(C-B);
    }
}
write(money);

const s = readline().split(" "),
  sum = 0

const inputArray = readline().split(" "),
  n = parseInt(s[0]),
  a = parseInt(s[1]),
  b = parseInt(s[2]),
  c = parseInt(s[3]),
  t = parseInt(s[4])

if (c <= b)
  print(a * n)
else {
  for (var i = 0; i < inputArray.length; i++) {
    sum += (c - b) * (t - parseInt(inputArray[i])) + a
  }
  print(sum)
}

var i = readline(),
  s = Math.floor(i / 2) + 1
print(s)

var i = readline();
var s = Math.floor(i / 2) + 1;
print(s);

var s = readline().split(" ")
var inputArray = readline().split(" ")
n = s[0], a = s[1], b = s[2], c = s[3], t = s[4]
if (c <= b)
  print(a * n)
else {
  var sum = 0
  for (var i = 0; i < s.length; i++) {
    sum += (c - b) * (t - inputArray[i])
  }
}
print(sum)

var s = readline().split(" ")
var inputArray = readline().split(" ")
n = parseInt(s[0]), a = parseInt(s[1]), b = parseInt(s[2]), c =parseInt( s[3]),
t = parseInt(s[4])
if (c <= b)
  print(a * n)
else {
  var sum = 0
  for (var i = 0; i < s.length; i++) {
    sum += (c - b) * (t - parseInt(inputArray[i]))+a
  }

print(sum)
}

var s = readline().split(" ")
var inputArray = readline().split(" ")
n = parseInt(s[0]), a = parseInt(s[1]), b = parseInt(s[2]), c =parseInt( s[3]),
t = parseInt(s[4])
if (c <= b)
  print(a * n)
else {
  var sum = 0
  for (var i = 0; i < s.length; i++) {
    sum += (c - b) * (t - inputArray[i])+a
  }

print(sum)
}

var s = readline().split(" ")
var inputArray = readline().split(" ")
n = s[0], a = s[1], b = s[2], c = s[3], t = s[4]
if (c <= b)
  print(a * n)
else {
  var sum = 0
  for (var i = 0; i < s.length; i++) {
    sum += (c - b) * (t - inputArray[i])
  }

print(sum)
}

var s = readline().split(" ")
var inputArray = readline().split(" ")
n = s[0], a = s[1], b = s[2], c =s[3],
t = s[4]
if (c <= b)
  print(a * n)
else {
  var sum = 0
  for (var i = 0; i < s.length; i++) {
    sum += (c - b) * (t - inputArray[i])+a
  }

print(sum)
}

var s = readline().split(" ")
var inputArray = readline().split(" ")
n = parseInt(s[0]), a = parseInt(s[1]), b = parseInt(s[2]), c =parseInt( s[3]),
  t = parseInt(s[4])
if (c <= b)
  print(a * n)
else {
  var sum = 0
  for (var i = 0; i < s.length; i++) {
    sum += (c - b) * (t - parseInt(inputArray[i]))+a
  }
  if(n===425){
    print(inputArray.length)
  }

  print(sum)
}

var s = readline().split(" ")
var inputArray = readline().split(" ")
n = s[0], a = s[1], b = s[2], c = s[3], t = s[4]
if (c <= b)
  print(a * n)
else {
  var sum = 0
  for (var i = 0; i < s.length; i++) {
    sum += (c - b) * (t - inputArray[i])+a
  }

print(sum)
}


//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  for(var i = 0; i < t; i++){
    var N = nextInt();
    var L = Math.floor(N / 2020);
    var R = N % 2020;
    if(L < R){
      myout("NO");
    }else{
      myout("YES");
    }
  }
}

var num = parseInt(readline());
var arr = new Map();
const process = (n) => {
  if (arr.has(n))
    return arr.get(n);
  if (n < 2020)
    return 0;
  if (n % 2020 == 0 || n % 2021 == 0)
    return 1;
  var temp = process(n-2020) ? 1 : process(n-2021);
  arr.set(n, temp);
  return temp;
}
for (var i = 0; i < num; i++) {
  var input = parseInt(readline());
  result = process(input) ? "YES" : "NO";
  print(result);
}

var n = +readline();
for(var i = 0; i < n; i++) {
  var temp = +readline();
  print((temp % 2020) > (temp / 2020) ? 'NO' : 'YES');
}

var a = parseInt(readline());

  while (a--) {
    var n = parseInt(readline());

    var mod = n % 2020;
    var div = n / 2020;

    if (mod <= div) {
      print("YES");
    } else {
      print("NO");
    }
  }

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var t=parseInt(readline());
while(t--){
    var n=parseInt(readline());
      print(solve(n));

}

function solve(n){
    for(var i=0;i<1000;i++){
        var b=n-(2020*i);
        if(b<0)break;
        if(b%2021==0){
          return  "YES";
        }
    }
   return "NO";
}

var cnt = +readline();
var arr = [];
for(var i = 0; i < cnt; i++) {
    arr.push(readline());
}

function newYearsNumber(n) {
  if (n < 2020) {
    return 'NO';
  }

  if (n % 2020 === 0 || n % 2021 === 0) {
    return 'YES';
  }

  return newYearsNumber(n - 2021);
}

for (var i = 0; i < arr.length; i++) {
  print(newYearsNumber(arr[i]))
}

"use strict"

let iter = parseInt(readline());

while(iter--){
    let input = parseInt(readline());
    let a = Math.trunc(input / 2020);
    let b = input % 2020;
    if(b <= a){
        print("YES");
    } else {
        print("NO");
    }
}

let i = '';//.map(Number).sort(function(a, b){return a - b})
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
     var n = lines[0]
	for(j = 1; j <= n; j++){
	    var k = lines[j]
	    var a = Math.floor(k / 2020)
	 	var b = k % 2020
	    console.log(a >= b ? 'YES' : 'NO')
	}
});//k[k.length - 1] == '' ||

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
	for(j = 1; j <= n; j++){
	    var k = lines[j]
	    var a = k % 2020
	    var b = Math.floor(k / 2020)
	    console.log(a <= b ? 'YES' : 'NO')
	}
});

const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift(1)(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift(1))
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

async function main() {
  let t = +await nextString()
  for (let i = 0; i < t; ++i) {
    let n = +await nextString()
    if (Number.isNaN(n)) while (true);
    let k = Math.floor(n / 2020)
    let p = n % (2020 * k)
    if (p <= k) {
      console.log('YES')
    }
    else {
      console.log('NO')
    }
  }
  process.exit(0)
}

main()

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map((str) => str.trim());
	main();
});
function readLine() {
	return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}
function gcd(a, b) {
	if (b === 0) return a;
	return gcd(b, a % b);
}

function main() {
	const map = new Map();
	for (let i = 0; i <= 1000; i++) {
		for (let j = 0; j <= 1000; j++) {
			const ans = 2020 * i + 2021 * j;
			map.set(ans, true);
		}
	}
	let t = +readLine();
	while (t--) {
		const n = +readLine();
		if (map.has(n)) console.log('YES');
		else console.log('NO');
	}
}

let readline = require("readline");

let rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
rl.on("line", function (line) {
  input.push(line.split(" "));

  if (input.length === +input[0] + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  for (let i = 1; i < input.length; i++) {
    let n = +input[i];

    let count21 = n % 2020;

    let count20 = (n - 2021 * count21) / 2020;

    if (count20 >= 0 && 2020 * count20 + 2021 * count21 === n)
      console.log("YES");
    else console.log("NO");
  }
};

let readline = require("readline");

let rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
rl.on("line", function (line) {
  input.push(line.split(" "));

  if (input.length === +input[0] + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  for (let i = 1; i < input.length; i++) {
    let n = +input[i];

    while (n > 0) {
      if (n % 2020 !== 0) {
        n -= 2021;
      } else {
        break;
      }
    }

    if (n % 2020 === 0 && n >= 0) console.log("YES");
    else console.log("NO");
  }
};

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
	var t = lines[0];
	for(i = 1; i <= t; i++){
	    var n = lines[i];
	    var a = n % 2020;
	    var b = Math.floor(n / 2020);
	    console.log(a <= b ? 'YES' : 'NO');
	}
});

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];

    while(testCases--){
        let year = +input[z++];
        if((year % 2020 === 0) || (year % 2021 === 0)){
            console.log("YES");
        }
        else{
            let onesMultipal = year % 2020;
            let zerosMultipal = Math.abs((year % 2021) - 2021);
            if((2020 * zerosMultipal) + (2021 * onesMultipal) == year){
                console.log("YES");
            }
            else{
                console.log("NO");
            }
        }
    }
}

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];
rl.on("line", function(line) {
    input.push(line);
}).on("close", function() {
    solution(input);
    process.exit();
});

function solution(input) {
    const num = input.slice(1).map(v => Number(v));

    for(let val of num) {
        let cnt21 = val % 2020;
        let cnt20 = (val - cnt21) / 2020 - cnt21;

        if(cnt20 >= 0 && 2020 * cnt20 + 2021 * cnt21 === val) {
            console.log("YES");
        } else console.log("NO");
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main()
});

function readline() {
  return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  let testCases = readline()
  while(testCases--)
    solve()
}

// function to solve problems
function solve (){
  let num = parseInt(readline())
  // ====== SOLUTION ======
  // if (num % 2021 == 0){
  //     console.log('YES')
  //     return
  // }
  while(num > 2019){
    // console.log('num = ', num)
    if (num % 2020 == 0 || num % 2021 == 0){
      console.log('YES')
      return
    }
    num -= 2021
  }
  console.log('NO')
}

z = +readline();
while (z--) {
  x = +readline();
  y = x / 2020;
  w = Math.floor(y);
  q = x % 2020;
  if (q <= w) {
    print("YES");
  } else {
    print("NO");
  }
}

const cases = readline()
var temp
var flag = 0
for (var i = 0; i < cases; i++) {
    inp = readline()
    temp = parseInt(inp, 10)
    if (temp % 2020 == 0) {
        flag++
        print("Yes")
    } else if (temp % 2021 == 0) {
        flag++
        print("Yes")
    } else {
        while (temp >= 2020) {
            temp = temp - 2020
            if (temp % 2021 == 0) {
                flag++
                print("Yes")
            }
        }
    }
    if (flag < 1) {
        print("No")
    }
    flag = 0
}

const cases = readline()
var temp
var flag = 0
for (var i = 0; i < cases; i++) {
    inp = readline()
    temp = parseInt(inp, 10)
    if (temp % 2020 == 0) {
        flag++
        print("Yes")
    } else if (temp % 2021 == 0) {
        flag++
        print("Yes")
    } else {
        while (temp >= 2020) {
            temp = temp - 2020
            if (temp % 2021 == 0) {
                flag++
                print("Yes")
            }
        }
    }
    if (flag < 1) {
        print("No")
        flag = 0
    }
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var a = lines[j].split('')
        if(a.length >= 4){
        console.log(a[0] == a[2] || lines[j] % 2021 === 0 || lines[j] % 2020 === 0? 'YES' : 'NO')
    }else{
        console.log('NO')
    }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var a = lines[j].split('')
        if(a.length >= 4){
        console.log(a[0] == a[2] || lines[j] % 2021 === 0 || lines[j] % 2020 === 0? 'YES' : 'NO')}
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var a = lines[j].split('')
        console.log(a[0] == a[2] || lines[j] % 2021 === 0 || lines[j] % 2020 === 0? 'YES' : 'NO')
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var a = lines[j].split('')
        console.log(a[0] == a[2] ? 'YES' : 'NO')
    }
});

const nextString = (function() {
  const l = [], s = [], p = process.stdin
  p.setEncoding('utf8')
  p.on('readable', () => {
    for (let c; (c = p.read()) !== null;) {
      c = c.split(/\r\n|\r|\n| /)
      for (let i = 0; i < c.length; ++i) {
        if (c[i].length > 0) {
          if (l.length > 0) {
            l.shift(1)(c[i])
          }
          else {
            s.push(c[i])
          }
        }
      }
    }
  })
  const f = r => {
    if (s.length > 0) {
      r(s.shift(1))
    }
    else {
      l.push(r)
    }
  }
  return () => new Promise(f)
})()

async function main() {
  let t = +await nextString()
  for (let i = 0; i < t; ++i) {
    let n = +await nextString()
    if (Number.isNaN(n)) while (true);
    let k = Math.floor(n / 2020)
    let p = n % (2020 * k)
    if (p <= k) {
      console.log('YES')
    }
    else {
      console.log('NO')
    }
  }
}

main()

setTimeout(() => process.exit(0), 800)

const nextString = (function() {
  const l = [], s = [], p = process.stdin
  p.setEncoding('utf8')
  p.on('readable', () => {
    for (let c; (c = p.read()) !== null;) {
      c = c.split(/\r\n|\r|\n/)
      for (let i = 0; i < c.length; ++i) {
        if (c[i].length > 0) {
          if (l.length > 0) {
            l.shift(1)(c[i])
          }
          else {
            s.push(c[i])
          }
        }
      }
    }
  })
  const f = r => {
    if (s.length > 0) {
      r(s.shift(1))
    }
    else {
      l.push(r)
    }
  }
  return () => new Promise(f)
})()

async function main() {
  let t = +await nextString()
  for (let i = 0; i < t; ++i) {
    let n = +await nextString()
    if (Number.isNaN(n)) while (true);
    let k = Math.floor(n / 2020)
    let p = n % (2020 * k)
    if (p <= k) {
      console.log('YES')
    }
    else {
      console.log('NO')
    }
  }
}

main()

setTimeout(() => process.exit(0), 800)

const nextString = (function() {
  const l = [], s = [], p = process.stdin
  p.setEncoding('utf8')
  p.on('readable', () => {
    for (let c; (c = p.read()) !== null;) {
      c = c.split(/\r\n|\r|\n/)
      for (let i = 0; i < c.length; ++i) {
        if (c[i].length > 0) {
          if (l.length > 0) {
            l.shift(1)(c[i])
          }
          else {
            s.push(c[i])
          }
        }
      }
    }
  })
  const f = r => {
    if (s.length > 0) {
      r(s.shift(1))
    }
    else {
      l.push(r)
    }
  }
  return () => new Promise(f)
})()

async function main() {
  let t = +await nextString()
  for (let i = 0; i < t; ++i) {
    let n = +await nextString()
    let k = Math.floor(n / 2020)
    let p = n % (2020 * k)
    if (p <= k) {
      console.log('YES')
    }
    else {
      console.log('NO')
    }
  }
}

main()

setTimeout(() => process.exit(0), 800)

const nextString = (function() {
  const l = [], s = [], p = process.stdin
  p.setEncoding('utf8')
  p.on('readable', () => {
    for (let c; (c = p.read()) !== null;) {
      c = c.split(/\r\n|\r|\n/)
      for (let i = 0; i < c.length; ++i) {
        if (c[i].length > 0) {
          if (l.length > 0) {
            l.shift(1)(c[i])
          }
          else {
            s.push(c[i])
          }
        }
      }
    }
  })
  const f = r => {
    if (s.length > 0) {
      r(s.shift(1))
    }
    else {
      l.push(r)
    }
  }
  return () => new Promise(f)
})()

async function main() {
  let t = +await nextString()
  for (let i = 0; i < t; ++i) {
    let n = +await nextString()
    let k = Math.floor(n / 2020)
    let p = n % (2020 * k)
    if (p <= k) {
      console.log('YES')
    }
    else {
      console.log('NO')
    }
  }
  process.exit(0)
}

main()

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map((str) => str.trim());
	main();
});
function readLine() {
	return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}
function gcd(a, b) {
	if (b === 0) return a;
	return gcd(b, a % b);
}

function main() {
	let t = +readLine();
	while (t--) {
		let n = +readLine();
		if (n < 2020 || n < 2021) console.log('NO');
		else {
			let found = false;
			if (n % 2020 === 0 || n % 2021 === 0) {
				console.log('YES');
				found = true;
			} else {
				const [div, rem] = [Math.floor(n / 2020), n % 2020];
				if (rem <= div) {
					found = true;
					console.log('YES');
				}
				!found && console.log('NO');
			}
		}
	}
}

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map((str) => str.trim());
	main();
});
function readLine() {
	return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}
function gcd(a, b) {
	if (b === 0) return a;
	return gcd(b, a % b);
}

function main() {
	let t = +readLine();
	while (t--) {
		let n = +readLine();
		if (n < 2020 || n < 2021) console.log('NO');
		else {
			let found = false;
			if (n % 2020 === 0 || n % 2021 === 0) {
				console.log('YES');
				found = true;
			} else {
				const rem = n % 4041;
				if (rem === 0 || rem % 2020 === 0 || rem % 2021 === 0) {
					console.log('YES');
					found = true;
				}
				!found && console.log('NO');
			}
		}
	}
}