"use strict";
const main = arg => {
  const input = arg.trim();

  const a = parseInt(input.split(" ")[0]);
  const b = parseInt(input.split(" ")[1]);

  (a % 2 !== 0 || b !== 0) ? console.log('Odd') : console.log('Even');
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


function main(input)
{
  const args = input.split(' ');
  const a = parseInt(args[0], 10);
  const b = parseInt(args[1], 10);

  if ((a*b) % 2 === 0) {
    console.log('Even');
  }
  else
  {
    console.log('Odd');
  }
}

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


function main(input) {
    let tmp = input.split(" ");
    let a = parseInt(tmp[0]);
    let b = parseInt(tmp[1]);
    console.log((a * b % 2 == 0) ? "Even" : "Odd");
}

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


function main(input) {
    const input = input.split(" ");
    let a = parseInt(input[0]);
    let b = parseInt(input[1]);
    const result = ((a * b) % 2 === 0) ? "Even" : "Odd";
    console.log(result);
}

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


function Main(input) {

    const numberList = input.split(' ')
	input1 = numberList[0];
  	input2 = numberList[1];

  	let a = input1;
  	let b = input2;

  	let sum = a * b;

    if(sum % 2 === 0) {
        console.log("Even");
    } else {
		console.log("Odd");
  	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
	const inputs = input.split(" ");

	const product = inputs.reduce((a, b) => a * b);
	const isEven = product % 2 === 0;
	console.log(isEven ? "Even" : "Odd");
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
	tmp = input.split(" ");
  	if((tmp[0]*tmp[1])%2==0){
    	console.log('Even')
    }else{
    	console.log('Odd')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {
	input = input.split(" ");
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
  	var s = a * b % 2;
  	if (s === 0) {
		console.log("even");
    } else {
      console.log("odd");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
  	var s = Math.floor(a * b % 2);
	//出力
  	if (s == 0) {
		console.log("even");
    } else {
      console.log("odd");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


const main = (val) => {
  const aray = val.split(" ");
  console.log(calc(aray));
}
const calc = (aray) => {
  if ((parseInt(aray[0]) % 2) === 0
     ||(parseInt(aray[1]) % 2) === 0) {
    return "Even";
  }
  return "0dd";
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
	input = input.split(" ");
	x = input[0];
	a = input[1];
	String(Math.sqrt(Number(String(x)+a))).indexOf('.') != -1?console.log('No'):console.log('Yes');
}

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


function main(input){
  input = input.split("");
  a = input[0];
  b = input[1]
  console.log(a * b % 2 === 0 ? "Even" : "0dd")
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
    input = input.split(" ");
    a=input[0];
    b=input[1];
    console.log((a*b)%2==0 ? "Even" : "Odd")
}

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


function main(input) {
	// 入力
	input = input.split(" ");
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
	var s = (a * b) / 2;
	// 出力
	if (Number.isInteger(s) == true) {
		console.log('Even');
	} else {
		console.log('Odd');
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


let main = (standardInput) => {
    let lengthList = standardInput.split(' ');
    let varticalLength = Number.parseInt(lengthList[0]);
    let horizonLength = Number.parseInt(lengthList[1]);

    console.log('Odd')
    //console.log(`${varticalLength * horizonLength} ${2 * (varticalLength + horizonLength)}`);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


function Main(input) {
  tmp = input.split(" ");
  var a = parseInt(tmp[0], 10);
  var b = parseInt(tmp[1], 10);
  var s = ((a * b) % 2 == 0) ? "Even" : "Odd";
  console.log('%s',s);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
    const inputs = input.split(' ');
    console.log(inputs[0] * inputs[1] % 2 === 0 ? 'Even' : 'Odd');
}

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


function Main(input){
    var tmp=input.split(" ");
    var a=parseInt(tmp[0],10);
    var b=parseInt(tep[1],10);
    var output_string=a*b%2==1?"Odd":"Even";
    console.log(output_string);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input){
    tmp=input.split(" ");
    var a=parseInt(tmp[0],10);
    var b=parseInt(tep[1],10);
    console.log(a*b%2?"Odd":"Even");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
	 const num = input.split(" ");
   const a = parseInt(num[0], 10);
   const b = parseInt(num[1], 10);
   const ans = a * b;
   if (ans % 2 === 0) {
     console.log("Even")
   }
   else{
     console.log("Odd")
   }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = '';
process.stdin.on('data', function(chunk) {
    lines += chunk;
});
process.stdin.on('end', function() {
    main(lines.split(/\r?\n/));
});
function main(inputs){
  var nums = inputs[0].split(" ");
  var a = nums[0];
  var b = nums[1];

  var product = a * b;

  if(product % 2 == 0){
    console.log("Even");
  } else {
    console.log("Odd");
  }

}


'use strict'

function main(s) {

  const input = s.replace(/\n/g, '').split(' ').map(x => Number(x));
  var result = ((input[0] * input[1]) % 2) === 0 ? 'Even' : 'Odd';
  console.log(result);
}

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


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	//input = input.split("\n");
	tmp = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
	var output_string="";
	output_string= a * b % 2 == 0 ? "Even" : "Odd" ;
	//出力
	console.log(output_string);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
	//出力
	if (a*b%2 == 1) {
        console.log("Odd");
    }
    if (a*b%2 == 0) {
        console.log("Even");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    input = input.split(' ');
    a = (input[0]);
    b = (input[1]);
    tunageru = a+b;
    tunageta = parseInt(tunageru);
    if (Math.sqrt(tunageta) % 1 === 0) {
        console.log('Yes');
    } else {
        console.log('No');
    }
}
 Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


let a=7
let b=5
if(a*b % 2 == 0){
  console.log("Even");
else{
  console.log("Odd");
}


function spilitInput(input) {
  var splited = [];
  var rows = input.split('\n');
  for (var i = 0; i < rows.length; i += 1) {
    splited.push(rows[i].split(' '));
  }
  return splited;
}
function Main(input) {
  var splited = spilitInput(input);
  var N = splited[0][0];
  var Y = splited[0][1];
  var ax = 10000;
  var ay = 5000;
  var az = 1000;
  var x = -1;
  var y = -1;
  var z = -1;
  var hit = false;
  for(var iz = 0; iz <= N && !hit; iz += 1) {
  for(var iy = 0; iy <= N && !hit; iy += 1) {
  for(var ix = 0; ix <= N && !hit; ix += 1) {
    var totalN = ix+iy+iz;
    if (totalN == N) {
      var total = (ax*ix)+(ay*iy)+(az*iz);
      if (total == Y) {
        x = ix;
        y = iy;
        z = iz;
        hit = true;
      }
    } else if (totalN > N) {
      break;
    }
  }
  }
  }
  console.log(x+' '+y+' '+z);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.

According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Constraints

1 ≤ N ≤ 2000

1000 ≤ Y ≤ 2 × 10^7

N is an integer.

Y is a multiple of 1000.

Input

Input is given from Standard Input in the following format:

N Y

Output

If the total value of N bills cannot be Y yen, print -1 -1 -1.

If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.

Sample Input 1

9 45000

Sample Output 1

4 0 5

If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct.

Sample Input 2

20 196000

Sample Output 2

-1 -1 -1

When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.

Sample Input 3

1000 1234000

Sample Output 3

14 27 959

There are also many other possibilities.

Sample Input 4

2000 20000000

Sample Output 4

2000 0 0


function main(input){
  var str = input.split(' ');
  var int = [];
  int.push(parseInt(str[0]));//入っているお札の枚数:N
  int.push(parseInt(str[1]));//合計金額:Y

  money:
  for(let i=0;i<=int[0];i++){
    for(let j=0;j<=int[0];j++){
      var com = 9*i+4*j;
      if(com === int[1]/1000-int[0]){
        var thou = int[0] - (i+j);
      	if(thou >=0){
          var fiveThou = j;
          var tenThou = i;
           break money;
        }else{
          continue;
        }
      }else{
        var thou = -1;
        var fiveThou = -1;
        var tenThou = -1;
      }
    }
  }
  console.log(tenThou+' '+fiveThou+' '+thou);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


"use strict";

function main(input){
  const args = input.trim().split(' ').map(_=>parseInt(_,10));
  const n = args[0];
  const y = args[1];

  for(let i=0; i<=n; i++){
    for(let k=0; k<=n-i; k++){
      const x = 10000*i + 5000*k + 1000*(n - i - k);
      if(x == y) {
        console.log([i,k,n-i-k].join(' '));
        return;
      }
    }
  }

  console.log("-1 -1 -1");
}

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


"use strict";
function Main(input) {
  input = input.split("\n");
  const totalNums = parseInt(input[0], 10);
  const otoshidamas = parseInt(input[1], 10);
  let result = "-1-1-1";

  for(let ichimanen = 0; ichimanen <= totalNums; ichimanen++){
      for(let gosenen = 0; gosenen <= totalNums; gosenen++){
          let senen = totalNums - (ichimanen + gosenen);
          let total = ichimanen + gosenen + senen;
          let otoshidamaSumTotal = (ichimanen*10000) + (gosenen*5000) + (senen*1000);
          if(total === totalNums && otoshidamaSumTotal === otoshidamas && senen >= 0){
              //result = "${ichimanen} ${gosenen} ${senen}"
              result = "(ichimanen)+(gosenen)+(senen)"
          }
      }
  }
  console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf-8"));


"use strict";

function Main(input) {
  input = input.split(" ");
  input[0] = parseInt(input[0]);
  input[1] = parseInt(input[1]);

  // const counter = [0, 0, 0];

  for (let counter1 = 0; counter1 <= input[0]; counter1++) {
    for (let counter2 = 0; counter2 <= input[0]; counter2++) {
      for (let counter3 = 0; counter3 <= input[0]; counter3++) {
        if (
          counter1 + counter2 + counter3 === input[0] &&
          counter1 * 10000 + counter2 * 5000 + counter3 * 1000 === input[1]
        ) {
          console.log(counter1, counter2, counter3);
          return;
        }
      }
    }
  }
  console.log(-1, -1, -1);
}

Main(require("fs").readFileSync("/dev/stdin", "utf-8"));


function main(input) {
  input = input.split(' ');
  var n = parseInt(input[0]);
  var m = parseInt(input[1]);
  for(var x = 0; x <= m; x += 10000) {
    for(var y = 0; y <= m - x; y += 5000) {
      var z = (m - x - y) % 1000;
      if (0 <= z && (x + y + (z * 1000 )) == m && ((x / 10000) + (y / 5000) + z) == n) {
        console.log(x / 10000 + ' ' + y / 5000 + ' ' + z);
        return;
      }
    }
  }
  console.log('-1 -1 -1');
}

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


'use strict'
function otoshidama(stdin) {
  const inputs = stdin.split(' ')
  const n = inputs[0]
  const y = inputs[1]
  for (let i = 0;i <= n;i++) {
    const remain = y - 10000 * i
    if (remain === 0 && n === i) {
      return console.log(n, 0, 0)
    } else if (remain <= 0 && i < n) {
      break
    }
    for (let j = 0;j <= n - i;j++) {
      const sen = n - i - j
      const result = remain - 5000 * j - 1000 * sen
      if (result === 0) {
        return console.log(i, j, sen)
      } else if (result < 1000) {
        break
      }
    }
  }
  return console.log(-1, -1, -1)
}
otoshidama(require('fs').readFileSync(0, 'utf8'))


'use strict'
function otoshidama(stdin) {
  const inputs = stdin.split(' ')
  const n = inputs[0]
  const y = inputs[1]
  for (let i = 0;i <= n;i++) {
    const remain = y - 10000 * i
    if (remain === 0 && n === i) {
      return console.log(n, 0, 0)
    } else if (remain < 0) {
      break
    }
    for (let j = 0;j <= n - i;j++) {
      const sen = n - i - j
      const result = remain - 5000 * j - 1000 * sen
      if (result === 0) {
        return console.log(i, j, sen)
      } else if (result < 1000) {
        break
      }
    }
  }
  return console.log(-1, -1, -1)
}
otoshidama(require('fs').readFileSync(0, 'utf8'))


'use strict'
function otoshidama(stdin) {
  const inputs = stdin.split(' ')
  const n = inputs[0]
  const y = inputs[1]
  for (let i = 0;i <= n;i++) {
    const remain = y - 10000 * i
    if (remain < 0) break
    for (let j = 0;j <= n - i;j++) {
      const sen = n - i - j
      const result = remain - 5000 * j - 1000 * sen
      if (result === 0) return console.log(i, j, sen)
      else if (result < 1000) break
    }
  }
  return console.log(-1, -1, -1)
}


function main(input){
  //入力値の分割
  var args = input.split(' ');
  var N = parseInt(args[0],10);
  var Y = parseInt(args[1],10);
  //入力値を元にしたお札の割当
  var result = "-1 -1 -1";
  for(var a =0; a <= N ; a++){
    for(var b =0; b <= (N-a); b ++){
      for(var c =0; c <= (N-a-b); c++){
        var sum = (c * 10000) + (b * 5000) + (a * 1000);
        if(sum === Y){
          result = `${c} ${b} ${a}`;
          break;
        }
      }
    }
  }
  //割当の結果の出力
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input){
  //入力値の分割
  var args = input.split(' ');
  var N = parseInt(args[0],10);
  var Y = parseInt(args[1],10);
  //入力値を元にしたお札の割当
  var result = "-1 -1 -1";
  for(var a =0; a <= N ; a++){
    for(var b =0; b <= (N-a); b ++){
      for(var c =0; c <= (N-a-b); c++){
        var sum = (c * 10000) + (b * 5000) * (a * 1000);
        if(sum === Y){
          result = `${c} ${b} ${a}`;
          break;
        }
      }
    }
  }
  //割当の結果の出力
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


// inputに入力データ全体が入る
function Main(input) {
	var input = input.split(" ");
  	var num = parseInt(input[0],10);
  	var money = parseInt(input[1],10);
  	var result = "-1 -1 -1";

  	// 1000円札
  	loop:
  	for(var i=0; i<=num; i++){
      // 5000円札
      for(var j=0; j<=num; j++){
        if(i+j>num){
           continue;
        }
        // 10000円札
        sum = (10000*(num-j-i)) + (5000*j) + (1000*i);
        if(sum == money){
           result = `${num-i-j} ${j} ${i}`;
           //result = (num-j-i)+" "+j+" "+i;
           break loop;
        }
      }
    }
	//出力
	console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


// inputに入力データ全体が入る
function Main(input) {
	var input = input.split(" ");
  	var num = parseInt(input[0],10);
  	var money = parseInt(input[1],10);
  	var result = "-1 -1 -1";

  	// 1000円札
  	loop:
  	for(var i=0; i<=num; i++){
      // 5000円札
      for(var j=0; j<=num; j++){
        if(i+j>num){
           continue;
        }
        // 10000円札
        sum = 10000*num-j-i + 5000*j + 1000*i;
        if(sum == money){
           result = (num-j-i)+" "+j+" "+i;
           break loop;
        }
      }
    }
	//出力
	console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input){
  var In = input.split(' ');
  var N = parseInt(In[0], 10);
  var Y = parseInt(In[1], 10);
  var yen10000 = -1;
  var yen5000 = -1;
  var yen1000 = -1;

  for(var i = 0; i <= N; i++){
    for(var j = 0; j <= N - i; j++){
      var k = N - i - j;
      var total = 10000 * i + 5000 * j + 1000 * k;
      if(total == Y){
        yen10000 = i;
        yen5000 = j;
        yen1000 = k;
      }
    }
  }
  console.log('%d %d %d', yen10000, yen5000, yen1000);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  const input_array = input.split(' ');
  const sum_price = input_array[1];
  const paper_money_count = input_array[0];

  if(sum_price > 10000 * paper_money_count || sum_price < 1000 * paper_money_count){
    console.log('-1 -1 -1');
  }

  for(count_10000=0; count_10000<=paper_money_count ;count_10000++){
    maximum_price = 10000 * count_10000 + 5000 * (paper_money_count - count_10000);
    minimum_price = 10000 * count_10000 + 1000 * (paper_money_count - count_10000);
    if(sum_price > maximum_price || sum_price < minimum_price){
      continue;
    }
    for(count_5000=0; count_5000<=paper_money_count - count_10000 ;count_5000++){
      maximum_price = 10000 * count_10000 + 5000 * (paper_money_count - count_10000) + 1000 * (paper_money_count - count_10000 - count_5000);
      if(sum_price > maximum_price){
        continue;
      }
      for(count_1000=0; count_1000<=paper_money_count - count_10000 - count_5000 ;count_1000++){
        if(count_10000 + count_5000 + count_1000 != paper_money_count){
          continue;
        }
        if(count_10000 * 10000 + count_5000 * 5000 + count_1000 * 1000 == sum_price){
          console.log(`${count_10000} ${count_5000} ${count_1000}`);
          return;
        }
      }
    }
  }

  console.log('-1 -1 -1');
}

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


function Main(input) {
  input = input.split(" ");

  var N = ~~input[0];
  var Y = ~~input[1];

  var You = function(N, Y){
    this.howMany = N;
    this.howMuch = Y;
  }

  You.prototype = {
    check: function(){
      var maxHowMany = this.howMuch/1000;
      for(var howMany10000yen = 0; howMany10000yen < maxHowMany; howMany10000yen++){
        for(var howMany5000yen = 0; howMany5000yen < maxHowMany; howMany5000yen++){
          for(var howMany1000yen = 0; howMany1000yen < maxHowMany; howMany1000yen++){
            var candidatePrice = howMany1000yen*1000 + howMany5000yen*5000 + howMany10000yen*10000;
            var candidateNum =  howMany1000yen + howMany5000yen + howMany10000yen;
            if(candidatePrice == this.howMuch && candidateNum == this.howMany) return String(howMany10000yen)+" "+String(howMany5000yen)+" "+String(howMany1000yen);
          }
        }
      }
      return "-1 -1 -1";
    }
  }

  var you = new You(N, Y);
  console.log(you.check());
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    var raw = input[0].split(" ");
    var N = parseInt(raw[0],10);
    var Y = parseInt(raw[1],10);
    var W = Y/1000;
    var flag = false;
    for(var z=0; z<=N; z++){
      var A = W-z
      if(A%5!==0) continue;
      var M = N-z;
      if(10*M >= A && A >= 5*M) {
        flag = true;
        var y = (10*M-A)/5;
        var x = M-y;
        console.log('%d %d %d',x,y,z);
        break;
      }
    }
    if(!flag) {
       console.log('%d %d %d',-1,-1,-1);
    }

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'

const main = (input) => {
    input = input.split(' ').map(v => parseInt(v))
    const N = input[0]
    const Y = input[1]
    let xCount = -1
    let yCount = -1
    let zCount = -1

    for(let x = 0; x <= N; x++){
        for(let y = 0; y <= N; y++){
            let z = N - x - y
            let total = 10000 * x + 5000 * y + 1000 * z
            if(z >= 0 && total === Y){
                xCount = x
                yCount = y
                zCount = z
                break
            }
        }
    }

    console.log("%d %d %d", xCount, yCount, zCount)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))


function main(input) {
    const args = input.split(' ');
    const N = parseInt(args[0], 10),
          Y = parseInt(args[1], 10);

    var result = '-1 -1 -1';

    for (var a = 0; a <= N; a++) {
        for (var b = 0; b <= N; b++) {
            if ((a + b) > N) {
                continue;
            }

            var sum = (a * 10000) + (b * 5000) + ((N - a - b) * 1000);
            if (sum === Y) {
                result = `${a} ${b} ${N - a - b}`;
                break;
            }
        }
    }

    console.log(result);

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


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

function calcBillSheets(num, yen) {
  var billComb = [num, 0, 0];
  var total;

  while ((total = totalSum(billComb)) > yen) {
    if (billComb[1] > 0 && total - yen > 5000) {
      billComb[1]--; billComb[2]++;
    } else if (billComb[0] > 0) {
      billComb[0]--; billComb[1]++;
    } else {
      return [-1, -1, -1];
    }
  }

  if (totalSum(billComb) === yen) {
    return billComb;
  } else {
    return [-1, -1, -1];
  }
}

function totalSum(billComb) {
  return billComb[0] * 10000 + billComb[1] * 5000 + billComb[2] * 1000;
}

process.stdin.on('data', function (line) {
  var arg = line.trim().split(' ');
  console.log(calcBillSheets(parseInt(arg[0]), parseInt(arg[1])).join(' '));
  process.exit(0);
});


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

function calcBillSheets(num, yen) {
  var billComb = [num, 0, 0];
  var total;

  while ((total = totalSum(billComb)) > yen) {
    if (billComb[1] > 0) {
      billComb[1]--; billComb[2]++;
    } else {
      billComb[0]--; billComb[1]++;
    }
  }

  if (totalSum(billComb) === yen) {
    return billComb;
  } else {
    return [-1, -1, -1];
  }
}

function totalSum(billComb) {
  return billComb[0] * 10000 + billComb[1] * 5000 + billComb[2] * 1000;
}

process.stdin.on('data', function (line) {
  var arg = line.trim().split(' ');
  console.log(calcBillSheets(parseInt(arg[0]), parseInt(arg[1])).join(' '));
  process.exit(0);
});


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    let H = parseInt(arg[0].split(" ")[1]);

    let AB = arg.slice(1, N + 1).map(n=>n.split(" ").map(l=>parseInt(l)));

    AB.sort((a,b)=>b[0] - a[0]);

    let throwSum = 0;
    const strongest = AB[0][0];

    for(let i=0; i<N; i++) {
        if(AB[i][1] > strongest) {
            throwSum += AB[i][1];
        }
    }

    let cnt = 0;

    // while(H > throwSum) {
    //     H -= AB[0][0];
    //     cnt++;
    // }

    // console.log("cnt" + cnt);

    cnt += Math.ceil(((H - throwSum) / strongest));
    H -= cnt * strongest;

    cnt = Math.max(0, cnt);

    if(H <= 0) {
        console.log(cnt);
        return;
    }

    AB.sort((a,b)=>b[1] - a[1]);

    for(let i=0; i<N; i++) {
        H -= AB[i][1];
        cnt++;

        if(H <= 0) break;
    }

    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:

Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.

Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.

The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Constraints

1 ≤ N ≤ 10^5

1 ≤ H ≤ 10^9

1 ≤ a_i ≤ b_i ≤ 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N H
a_1 b_1
:
a_N b_N

Output

Print the minimum total number of attacks required to vanish the monster.

Sample Input 1

1 10
3 5

Sample Output 1

3

You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.

Sample Input 2

2 10
3 5
2 6

Sample Output 2

2

In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.

Sample Input 3

4 1000000000
1 1
1 10000000
1 30000000
1 99999999

Sample Output 3

860000004

Sample Input 4

5 500
35 44
28 83
46 62
31 79
40 43

Sample Output 4

9


var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextStrArray();
  var N = one[0];
  var H = one[1];
  var alist = new Array(N);
  var blist = new Array(N);
  for(var i = 0; i < N; i++){
    var tmp = nextIntArray();
    alist[i] = tmp[0];
    blist[i] = tmp[1];
  }
  var amax = Math.max.apply(null,alist);
  var output = 0;
  for(var i = 0; i < N; i++){
    if(blist[i] >= amax){
       H -= blist[i];
       output++;
       if(H <= 0){
          myout(output);
         return;
       }
    }
  }
  output += Math.ceil(H / amax);
  myout(output);
}


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

var lines = [];
reader.on('line', function(line) {
  lines.push(line);
});

reader.on('close', function() {
  var words = lines[0].split(' ');
  var N = Number(words[0]), H = Number(words[1]);

  var B = [], amax = 0;
  for(var i=1; i<=N; ++i) {
    var ab = lines[i].split(' ').map(Number);
    amax = Math.max(amax, ab[0]);
    B.push(ab[1]);
  }
  B.sort(function(x,y){return y-x;})

  var ans=0;
  for(var i=0; i<N && B[i]>amax && H>0; ++i) {
    ans+=1;
    H -= B[i];
  }

  H = Math.max(H,0);
  ans += Math.ceil(H/amax);

  console.log(ans);

});


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

var lines = [];
reader.on('line', function(line) {
  lines.push(line);
});

reader.on('close', function() {
  var words = lines[0].split(' ');
  var N = Number(words[0]), H = Number(words[1]);

  var B = [], amax = 0;
  for(var i=1; i<=N; ++i) {
    var ab = lines[i].split(' ').map(Number);
    amax = Math.max(amax, ab[0]);
    B.push(ab[1]);
  }
  B.sort(function(x,y){return y-x;})

  var ans=0;
  for(var i=0; i<N && B[i]>amax; ++i) {
    ans+=1;
    H -= B[i];
  }

  H = Math.max(H,0);
  ans += Math.floor((H+amax-1)/amax);

  console.log(ans);

});


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

var lines = [];
reader.on('line', function(line) {
  lines.push(line);
});

reader.on('close', function() {
  var words = lines[0].split(' ');
  var N = Number(words[0]), H = Number(words[1]);

  var B = [], amax = 0;
  for(var i=1; i<=N; ++i) {
    var ab = lines[i].split(' ').map(Number);
    amax = Math.max(amax, ab[0]);
    B.push(ab[1]);
  }
  B.sort(function(x,y){return y-x;})

  var ans=0;
  for(var i=0; i<N && B[i]>amax; ++i) {
    ans+=1;
    H -= B[i];
  }

  H = Math.max(H,0);
  ans += Math.ceil(H/amax);

  console.log(ans);

});


module.exports=function(r){var t={};function e(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)e.d(n,o,function(t){return r[t]}.bind(null,o));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=0)}([function(r,t,e){e(1)(e(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,t){function e(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var e=[],n=!0,o=!1,u=void 0;try{for(var i,a=r[Symbol.iterator]();!(n=(i=a.next()).done)&&(e.push(i.value),!t||e.length!==t);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==a.return||a.return()}finally{if(o)throw u}}return e}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var t=e(r[0].split(" ").map(function(r){return Number(r)}),2),n=t[0],o=t[1],u=[],i=0,a=0;a<n;a++){var f=e(r[a+1].split(" ").map(function(r){return Number(r)}),2),l=f[0],c=f[1];u.push({a:l,b:c}),i<l&&(i=l)}for(var p=0,s=0;s<n;s++)p+=Math.max(u[s].b,i);var d=o-p;if(d<=0){var b=m(o);console.log(b)}else{var v=Math.ceil(d/i),y=v+m(o-v*i);console.log(y)}function m(r){u.sort(function(r,t){return t.b-r.b});for(var t=0;t<n;t++){if(r<=0)return t;r-=Math.max(u[t].b,i)}return n}}},function(r,t){r.exports=require("fs")}]);


var lines = [];
var readline = require('readline');

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

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0].split(" ")[0])
    var H = Number(lines[0].split(" ")[1]);

    lines.shift();

    var AB = lines.map(i => i.split(" ").map(i => Number(i)));

    var x = AB.concat().sort((a, b) => b[0] - a[0]);
    var y = AB.concat().sort((a, b) => b[1] - a[1]);

    var max = x[0][0];
    var damage = 0; var ans = Math.ceil(H / max);

    // 切りつけ攻撃力最大の刀で切り続け，最後に任意の刀を投げる
    for (var i = 0; i < N; i++) {
        damage += y[i][1];

        // 切りつけ攻撃回数が負になる場合，0とする
        var m = Math.ceil((H - damage) / max)
        if (m < 0) { m = 0 }

        ans = Math.min(ans, m + i + 1)
    }
    console.log(ans);
});


// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var tmp = line[0].split(" ");
	var numSword = Number(tmp[0]);
	var HP = Number(tmp[1]);
	var ans = 0;

	var throwDamage = [];
	var maxCutDamage = 0;
	for(var i = 1; i <= numSword; i++){
		throwDamage[i-1] = Number(line[i].split(" ")[1]);
		var cutDamage = Number(line[i].split(" ")[0]);
		if(maxCutDamage <= cutDamage) maxCutDamage = cutDamage;
	}

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

	var sumThrowDamage = 0;
	var throwTimes = 0;

	for(i = 0; i < throwDamage && throwDamage[i] > maxCutDamage; i++){
		throwTimes++;
		sumThrowDamage += throwDamage[i];
		if(HP <= sumThrowDamage){
			console.log(throwTimes);
			return false;
		}
	}

	var cutTimes = Math.ceil((HP-sumThrowDamage)/maxCutDamage);
	ans = cutTimes + throwTimes;
	console.log(ans);
	return false;

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function spilitInput(input) {
  var splited = [];
  var rows = input.split('\n');
  for (var i = 0; i < rows.length; i += 1) {
    splited.push(rows[i].split(' '));
  }
  return splited;
}
function Main(input) {
  var splited = spilitInput(input);
  var n = splited[0][0];
  var a = splited[0][1];
  var b = splited[0][2];
  var s_total = 0;
  for (var i = 1; i <= n; i += 1) {
    var sum = 0;
    String(i).split('').forEach(function(i_n){ sum += parseInt(i_n,10); });
    if (a <= sum && sum <= b) {
      s_total+=i;
    }
  }

  console.log(s_total);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Constraints

1 \leq N \leq 10^4

1 \leq A \leq B \leq 36

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Sample Input 1

20 2 5

Sample Output 1

84

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.

Sample Input 2

10 1 2

Sample Output 2

13

Sample Input 3

100 4 16

Sample Output 3

4554


function main(input) {
  let args = input.split(/\s/);
  let result = 0;
  for (let i = 0;i <= args[0];i++) {
    let sum = 0;
    for (let j = 0;j < ((i + '').length);j++) {
      sum += ((i + '')[j]) * 1;
    }
    if (sum >= args[1] && sum <= args[2]) {
      result += i;
    }
  }
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


const input = require("fs").readFileSync("/dev/stdin", "utf8").split(/\s/);

var ret = 0;
for (var i = 1; i <= input[0] - 0; i++) {
  var s = i.split("");
  var sum = s.map(Number).reduce(function (a, b) {
    return a + b;
  });

  if (input[1] <= sum && sum <= input[2]) ret += i;
}

console.log(ret);


// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");

var sum=0;
const limitBtm = Number(tmp[1]);
const limitTop = Number(tmp[2]);

for (i=1; i <= Number(tmp[0]); i++){
    var totalEach = 0;
    for(j=0; j<tmp[0].length; j++){
        totalEach += Number(String(i).substr( j, 1 ));
    }
    if(totalEach>=limitBtm && totalEach<=limitTop){
        sum+=i;
    }
}

	//出力
	console.log(sum);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  const arr = input.split(' ').map(x => Number(x));
  var total = 0;

  for (var i = 1; i <= arr[0]; i++) {
    var sum = Array.from(String(i)).map(x => Number(x)).reduce((a,c) => a + c);
    if (arr[1] <= sum && sum <= arr[2]) {
      total += i;
    }
  }

  console.log(total);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  const arr = input.split(' ').map(x => Number(x));
  var total = 0;

  for (var i = 1; i <= arr[0]; i++) {
    var sum = Array.from(String(i)).map(x => Number(x)).reduce((a,c) => a + c);
    if (arr[1] <= sum && sum <= arr[2]) {
      console.log(sum, i);
      total += i;
    }
  }

  console.log(total);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


// ABC 083

// inputに入力データ全体が入る
function Main(input) {
  input = input.split(" ");
  const N = parseInt(input[0],10);
  const A = parseInt(input[1],10);
  const B = parseInt(input[2],10);

  var arr = new Array() //A以上B以下の数値を一時的に入れる配列

  for(var n=0;n<=N;n++) {
    var tmp = n.toString().split(""); //一桁ごとに抽出
    var number = 0;

    // 抽出した値を一桁ずつ加算
    for(var t=0;t<tmp.length;t++) {
      number += parseInt(tmp[t],10);
    }

    if(number >= A && number <= B) arr.push(n);
  }

  var sum = 0; //合計の値
  for(var a=0;a<arr.length;a++) {
    sum += arr[a];
  }

  console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict"

const main =(input)=>{
  const array =input.split(" ")
  const N = array[0]-0
  const A = array[1]-0
  const B = array[2]-0

  let result = 0;
  for (let i=0; i<=N; i++){
   const sum= i.toString().split("").reduce( (a,b)=>(a-0)+(b-0) )
    if (A<=sum && B>=sum) result+=i ;
  }
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


const fs = require('fs');

function divmod(a, b) {
  var q = Math.floor(a / b);
  var r = a % b;
  return [q, r]
}

function main(input) {
  var arr = input.split(' ');
  arr = arr.map((n) => parseInt(n, 10));
  n = arr[0]; a = arr[1]; b = arr[2];

  var res = 0;
  var tot;
  var q;
  var r;
  var d;
  for (var i = 0; i <= n; i++) {
    q = i;
    tot = 0;
    while (q) {
      d = divmod(q, 10);
      q = d[0]; r = d[1];
      tot += r;
    }
    if (a <= tot && tot <= b) {
      res += i;
    }
  }
  console.log(res);
}

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


function main(input) {
  const args = input.split(' ');
  const N = parseInt(args[0]);
  const A = parseInt(args[1]);
  const B = parseInt(args[2]);

  const nums = Array.from(new Array(N), (v, i) => ++i).filter((i) => {
  	var n = i.toString().split('').reduce((p, c) => p + parseInt(c), 0);
    return (A <= n && n <= B);
  });

  console.log(nums.reduce((p, c) => p + c, 0));
}

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


function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input.trim());
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var N = input[0];
  var A = input[1];
  var B = input[2];
  var output = 0;
  for(var i = 1; i <= N; i++){
    var tmp = i.toString().split("");
    var digitSum = 0;
    for(var j = 0; j < tmp.length; j++){
      digitSum += parseInt(tmp[j]);
    }
    if(digitSum >= A && digitSum <= B){
       output += i;
       }
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


function main(input) {
  input=input.trim();
  const n = parseInt(input.split(" ")[0], 10);
  const a = parseInt(input.split(" ")[1], 10);
  const b = parseInt(input.split(" ")[2], 10);

  var ans=[]
  for(var i=1; i<=n; i++){
    var nagasa=String(i).length
    var wa=0
    for(var j=0; j<nagasa; j++){
      wa+=Number(String(i).substr(j,1))
    }
    if(wa>=a&&wa<=b){
      ans.push(i)
    }
  }
  //console.log(ans);
  console.log(ans.reduce((x,y)=>x+y));
}

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


process.stdin.resume();
process.stdin.setEncoding('utf8');

function splitDegistSum(number)
{
    var sum = 0, num = number;
    while (num > 0) {
        sum += num % 10;
        num = num / 10;
    }

    return parseInt(sum);
}

function Main(input) {
    var inputs = input.split(" ").map(e => parseInt(e));

    var N = inputs[0],
        A = inputs[1],
        B = inputs[2],
        result = 0;

    for (var i = 1; i <= N; i++) {
        var sum = splitDegistSum(i);
        if (A <= sum && sum <= B) {
            result += i;
        }
    }

    console.log(result);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  var In = input.split(' ');
  var N = In[0];
  var A = In[1];
  var B = In[2];

  var sum = 0;

  for(var i = 1; i <= N; i++){
    var str = String(i);
    var array = str.split('');
    var length = array.length;
    var strSum = 0;

    for(var j = 0; j < length; j++){
      var num = parseInt(array[j], 10);
      strSum += num;
    }

    if(A <= strSum){
      if(strSum <= B){
        sum += strSum;
      }
    }
  }

  console.log(sum);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  input = input.split(" ");
  var count = 0;
  for(var i=1;i<=input[0];i++){
    var tmp=0;
    for(var j of i.toString()){
      tmp+=Number(j);
    }
    if((input[1]<=tmp)&&(input[2]>=tmp)){
      count++;
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(count);


function Main(input) {
  input = input.split("\n");
  var count = 0;
  for(var i=1;i<=input[0];i++){
    var tmp=0;
    for(var j of i.toString()){
      tmp+=Number(j);
    }
    if((input[1]<=tmp)&&(input[2]>=tmp)){
      count++;
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(count);


function Main(input) {
  input = input.split('\n')

  let ans = 0

  const args = input[0].split(' ')
  const min = Number(args[1])
  const max = Number(args[2])

  const num = Number(args[0])

  for (let i = 1; i <= num; i++) {
    const splitNum = String(i).split('')

    let sum = 0
    splitNum.forEach(data => {
      sum = sum + Number(data)
    })

    if (min <= sum && sum <= max) ans = ans + i
  }

  console.log(ans)

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))


function Main(input) {
  input = input.split(" ");

  var N = ~~input[0];
  var A = ~~input[1];
  var B = ~~input[2];

  var Problem = function(){
    this.N = N;
    this.A = A;
    this.B = B;
  }

  Problem.prototype = {
    procedure: function(){
      var count = 0;
      for(var i=1; i<=N; i++){ // 1, 2, 3, 4, 5....1234,1235,1236...
        var numArray = String(i).split("").map(x => ~~x); //1234 => [1,2,3,4]
        var sum=0;
        for(eachNum of numArray){
          sum = sum+eachNum; // 1+2+3+4
        }
        if(this.A <= sum && sum <= this.B){
          //console.log(sum);
          count=count+i; // count=0+1234;
        }
      }
      return count;
    }
  }

  var problem = new Problem();
  console.log(problem.procedure());

  // console.log('%d %d',N,Q);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";

var main = function main(input) {
  var N = parseInt(input.split(" ")[0]);
  var A = parseInt(input.split(" ")[1]);
  var B = parseInt(input.split(" ")[2]);
  var count = 0;

  for (var i = 1; i <= N; i++) {
    var sum = 0;
    var arr = i.toString().split("");
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var c = _step.value;
        sum += parseInt(c, 10);
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    if (sum <= B && sum >= A) {
      count += i;
    }
  }

  console.log(count);
};

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


'use strict';

let execute = input => {
  const [N, A, B] = input.split(' ').map(str => +str);
  let ans = 0;
  for (let i = 1; i <= N; i++) {
    const sum = String(i).split('').reduce((sum, el) => sum += +el, 0);
    if (sum >= A && sum <= B) ans += i;
  }
  return ans;
};

function Main(input) {
  console.log(execute(input));
}

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


function main(input) {
    const args = input.split(' ');
    const N = parseInt(args[0], 10),
          A = parseInt(args[1], 10),
          B = parseInt(args[2], 10);

    const nums = Array.from(new Array(N), (v, i) => ++i).filter((i) => {
        var n = i.toString().split('').reduce((p, c) => p + parseInt(c), 0);
        return (n >= A && n <= B);
    });

    console.log(nums.reduce((p, c) => p + c, 0));
}

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


'use strict'

function main(input) {

    input = input.split(/\n|\s/).map(v => ~~v)
    const n = input[0]
    const a = input[1]
    const b = input[2]

    let total = 0
    for (let i = 1; i <= n; i++) {

        let tmp = i.toString().split('').map(v => ~~v).reduce((a, b) => a + b)

        if (a <= tmp && tmp <= b) {
            total += i
        }

    }
    console.log(total)

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


"use strict";

/**
 * @see https://practice.contest.atcoder.jp/tasks/practice_1
 * @param  {string} input
 * @returns {string}
 */
var main = function(input) {
    const digits = (n) => {
        return n.toString()
            .split("")
            .reduce((a, b) => a + b);
    }

    const params = input.split(" ").map(x => parseInt(x));
    const N = params[0];
    const A = params[1];
    const B = params[2];

    return [...Array(N).keys()]
        .map(x => x + 1)
        .filter(x => {
            const d = digits(x);
            return d >= A && d <= B;
        }).reduce((a, b) => a + b, 0);
};

const output = main(require("fs").readFileSync("/dev/stdin", "utf8"));
console.log(output); // console.log outputs with trailing new line!


// inputに入力データ全体が入る
function Main(input) {
	var args = input.split(" ");
	var N = parseInt(args[0],10);
	var min = parseInt(args[1],10);
	var max = parseInt(args[2],10);
	var array = [];
	var sum = 0;
	var answer = 0;

	for(var i = 0;i <= N;i++){
		sum = 0;
		var num_string = i + "";
		var num_array = num_string.split("");
		for(var j in num_array){
		sum += parseInt(num_array[j],10);
		}
		if(sum >= min && sum<= max) array.push(i);
	}

	for(var i =0;i < array.length; i++){
		answer += array[i];
	}
	//出力
	console.log(answer);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main (input) {
    var N = parseInt(input.split(' ')[0],10);
    var A = parseInt(input.split(' ')[1],10);
    var B = parseInt(input.split(' ')[2],10);
    var ans =0;

    for (var n=0;n<=N;n++) {
      var sum =0;
        sum = findSumOfDigits(n);
        if (Math.floor(sum) >= A && Math.floor(sum) <= B) {
            ans = ans + n;
        }
    }

    function findSumOfDigits(n) {
        while (n >0) {
            sum = sum + n%10;
            n = n/10;
        }
        return sum;
    }
    console.log(ans);
}

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


function Main(input){
  var N = parseInt(input.split(' ')[0]);
  var A = parseInt(input.split(' ')[1]);
  var B = parseInt(input.split(' ')[2]);

  var sum = 0;
  for(var i = 1; i <= N; i++){
    var is = i.toString().split('')
      .map((a) => parseInt(a, 10)).reduce((b, c) => { return b + c });

    if(A <= is && is <= B){
      sum += i;
    }
  }
  console.log(sum);
}

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


// inputに入力データ全体が入る
function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");

	//文字列から10進数に変換するときはparseIntを使います
	var N = parseInt(tmp[0], 10);
	var A = parseInt(tmp[1], 10);
	var B = parseInt(tmp[2], 10);

	var count=0;
	var sum=0;

	var iti;
	var zyuu;
	var hyaku;
	var sen;
	var man;

	for(i=1; i<=N; i++){

		iti = i % 10;
		zyuu = i % 100 - iti;
		hyaku = i % 1000 - iti - zyuu*10;
		sen = i % 10000 - iti - zyuu*10 - hyaku*100;
		man = i - iti - zyuu*10 - hyaku*100 -sen * 1000;

		sum = iti + zyuu + hyaku + sen + man;

		if(sum <= B && sum >= A){

			count = count +sum;

		}

	}

	//出力
	console.log('%d',count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


// inputに入力データ全体が入る
function Main(input) {
  var input = input.split('\n');
  var answer;

  var nums = input[0].split(' ');
	var n = nums[0];
	var a = nums[1];
	var b = nums[2];

	function matches(x) {
		return (x >= a && x <= b);
	}

	function sumOfDigits(x) {
		var digits = x.toString(10).split('');
		var sum =
			digits.reduce((ac, v) => parseInt(ac) + parseInt(v));
		return sum;
	}

	answer = 0;

	for (var i = 1; i <= n; i++) {
		var sum = sumOfDigits(i);

		if (matches(sum)) {
			answer += i;
		}
	}

	// 出力
  console.log(answer);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


let [a, b, c] = require("fs").readFileSync("/dev/stdin", "utf8").split("").map(Number);
console.log(a + b + c);

Score : 100 points

Problem Statement

Snuke has a grid consisting of three squares numbered 1, 2 and 3.
In each square, either 0 or 1 is written. The number written in Square i is s_i.

Snuke will place a marble on each square that says 1.
Find the number of squares on which Snuke will place a marble.

Constraints

Each of s_1, s_2 and s_3 is either 1 or 0.

Input

Input is given from Standard Input in the following format:

s_{1}s_{2}s_{3}

Output

Print the answer.

Sample Input 1

101

Sample Output 1

2

A marble will be placed on Square 1 and 3.

Sample Input 2

000

Sample Output 2

0

No marble will be placed on any square.


function Main(input) {
  let counter;
  const s = input.split("");
  if (s[0] == 1) counter++;
  if (s[1] == 1) counter++;
  if (s[2] == 1) counter++;

  console.log(counter);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input){
  console.log(input.split('1').lengh-1);

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


/// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	tmp = input[1].split(" ");

	//出力
  	var num = 0;
  while(true){
	for(i=0;i<input[0];i++){
		if(tmp[i]%2==0){
        	tmp[i]=tmp/2;
        }else{
        	break;
        }
      num ++;
    }
}
	console.log(num);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  var nums = input.split("\n")[1].split(" ").map(function (n) {
     return parseInt(n, 10);
  });

    var count = 0;
    while (
      nums.every(function (n) {
        return n % 2 === 0;
      })
    ) {
      count++;
      nums = nums.map(function (n) {
        return n / 2;
      });
    }

    console.log(count);
}

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


function Main(input) {
	var sum = 0;
	var inp = input.split("");
    inp.pop();
    inp.map( x => parseInt(x, 10) ).forEach( x => ( sum += x ) );
	console.log('%d',sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'

function Main(input) {
  const inputList = input.split('');
  let count = 0;

  for (let i=0; i<inputList.length; i++) {
    if (inputList[i] === '1') count++
  }
  console.log(count)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  const nums=input.split("");
  // nums=["1","0","0"];
  let sum=0;
  for(let i=0;i<=2;i++){
   if(nums[i]=="1")sum++;
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
    const args = input.split('');
    var cnt = 0;
    args.forEach((a) => {
      if(a === 1) {
        cnt + 1
      }
    })
    console.log(cnt);
}

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


'use strict';

function main(input) {
  console.log(input.split('1').length - 1);
}

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


function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    var count = 0;
    for (var i = 0; i < input.length; i++) {
        count  += parseInt(input[i]);
    }
    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main (input) {
  console.log(input.split('1').length -1);
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


const main = (input)=>{
  const array =input.split("\n").spilit(" ").map((n)=>{parseInt(n,10)})

  for(let result=1; array.every((n)=>{n%2==0}); result+=1 ){

   console.log(result)

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


function main(input) {
  var count = 0;
  for (let i = 0; i < 3; i++) {
    if (input[i] === "1") count++;
  }
  console.log(count);
}

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


function main(input) {
  const args = input.split(" ");
  const sss = args[0];
  let count = 0;
  sss.split("").forEach(
    () => count++
  );
  return count;
}

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


function main(input) {
	var result = 0;
	for(var i = 0; i < 3; i++) {
		if(input[i] == '1') {
			result += 1;
		}
	}
	console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	var input = input.split("\n");
    var sum = 0;
	for (  var i = 0;  i < 3;  i++  ) {
      sum = sum + parseInt(input.charAt(i), 10);
    }
	//出力
	console.log('%d',sum);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  var cnt = 0;
  for (var i = 0; i < 3; ++i) {
    if (input[i] === '1') {
      ++cnt;
    }
  }
  console.log(cnt);
}

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


'use strict';

const main=(input)=>{
  const args = input.trim().split('\n');
  const quantity = args[0];
  const nums = args[1].split(' ');
  let count = 0;

  for(i=0, i < quantity,i++){
    while(nums[i]%2===0){
      nums[i] = nums[i] / 2;
      count +=1;
  }
  console.log(count);
 }
}

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


'use strict';

const main=(input)=>{
  let count = 0;
  const args = input.trim().split('');
  const num1 = args[0];
  const num2 = args[1];
  const num3 = args[2];

  if(num1 ==='1' ){
    count += 1;
  };
  if(num2 ==='1'){
    count += 1;
  };
  if(num3 ==='1'){
    count += 1;
  };
  console.log(count);
};

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


function main(input){
  let count = 0;
  const args = input.trim().split('');
  const num1 = args[0];
  const num2 = args[1];
  const num3 = args[2];

  if(num1 ==='1' ){
    count += 1;
  };
  if(num ==='1'){
    count += 1;
  };
  if(num3 ==='1'){
    count += 1;
  };
  console.log(count);
};

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


function main(input) {
    const splitInput = input.replace(/0/g,'');
    console.log(splitInput.length);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
    const splitInput = input.replace('0','');
    console.log(splitInput.length);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
  var nums = input.split('\n')[1].split(' ').map((n) =>parseInt(n,10));
  var count = 0;
  while (nums.every((n) => (n % 2) === 0)) {
   count++;
   nums = nums.map((n) => n/2)

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


function main(input) {
    console.log(input.split("1").length-1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input){
  	var num = input.split("\n");
  	var elem = num[1].split(" ").map(str => parseInt(str, 10));

  	var count = 0;
  	inf_loop:
  	while(1){
      tmp = elem;
      for(var i=0; i<num[0]; i++){
      	if(elem[i]%2==0){
          tmp[i] = tmp[i]/2;
        }else{
          break inf_loop;
        }
      }
      count+=1;
      elem = tmp;
    }
  	console.log("count: "+count);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'

let Main = (input) => {
  let v = []
  v[0] = input.substr(0,1)
  v[1] = input.substr(1,1)
  v[2] = input.substr(2,1)
  let count = 0
  for(let i=0; i <= v.length-1; i++){
    if(v[i] == '1') count++
  }
  console.log(count)
}

Main(require("fs").readFileSync("/dev/stdin","utf8"))


function main(input) {
    console.log((input.match("1") || []).length);
}


function main(input) {
  input=input.trim();
  const a = parseInt(input.split("")[0], 10);
  const b = parseInt(input.split("")[1], 10);
  const c = parseInt(input.split("")[2], 10);
  var ans=0;
  if(a==1) ans++
  if(b==1) ans++
  if(c==1) ans++
  console.log(ans);

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


function main (arg) {
  var count = 0
  arg.split('').forEach(a => {
  	if (a === "1") count++
  })
  console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))


function Main(input) {
	const inputs = input.split("");

	const trueSquare = inputs.filter(square => parseInt(square) === 1);
	console.log(trueSquare.length);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
 var In = input.split('');
  var count = 0;

  for(var i = 0; i < 3; i++){
    if(In[i] == '1'){
      count += 1;
    }
  }
  console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input){
    var array = input.split('')
    var counter = 0

    if(parseInt(array[0],10)==1){
        counter +=1
    }
    if(parseInt(array[1],10)==1){
        counter +=1
    }
    if(parseInt(array[2],10)==1){
        counter +=1
    }
    console.log('%d', counter)
}

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


function main(input){
    var array = input.split("0")
    console.log(array.length-1)
}

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


function main(input) {
console.log(3)
}

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


function main(input) {
console.log((input+"").replace(/0/g,'').length)
}

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


process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!

function main(input) {
    console.log(input.split("1").length - 1)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


const Main = (input) => {
  var arr = input.split('');
  var count = 0;
  for(var i=0, l=arr.length; i<l; i++) {
    if(arr[i] === '1') count++;
  }
  console.log(count);
};

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


function Main(input) {
  input = input.split('\n')
  let args = input[1].split(' ')

  let ans = 0

  while (true) {
    const isEven = args.every(data => data % 2 == 0)

    if (isEven) {
      args = args.map(data => Number(data) / 2)
      ans++
    } else {
      console.log(ans)
      break
    }
  }

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))


function main(input: string): void {
  const result: string[] = input.split('').filter((arg: string) => {
    return arg === '1'
  })
  console.log(result.length)
}

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


function main(input) {
    const args = input.split('');
    var cnt = 0;
    if(args[0]==='1'){
        cnt++;
    }
    if(args[1]==='1'){
        cnt++;
    }
    if(args[2]==='1'){
        cnt++;
    }
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
    console.log(input.split('1').length - 1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input){
  var inp = input.split('');

  var count = 0;
  for(var i of inp){
    i === '1' ? count += 1 : '';
  }
  console.log(count);
}

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


function Main(inp) {
    console.log(inp.split("1").length-1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
S = inp.shift()
T = inp.shift()
for (i=S.length-1; i>=0; i--) {
    f = 1
    for (j=0; j<T.length; j++) {
        if (!(S[i+j] == T[j] || S[i+j] == '?')) {
            f = 0
        }
    }
    if (f==1) {
        break;
    }
}
if (f==1) {
    ans = ''
    for (k=0; k<S.length; k++) {
        if (k == i) {
            ans += T
            k += T.length - 1
        } else {
            ans += S[k] == '?' ? 'a' : S[k]
        }
    }
} else {
    ans = 'UNRESTORABLE'
}
console.log(ans)

Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.

One more thing he found is a sheet of paper with the following facts written on it:

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0];
    const T = arg[1];

    for(let i=S.length - T.length; i>=0; i--) {
        let flag = true;
        let sub  = S.substr(i, T.length);

        for(let j=0; j<T.length; j++) {
            if(sub.charAt(j) !== T.charAt(j) && sub.charAt(j) !== "?") {
                flag = false;
                break;
            }
        }

        if(flag === true) {
            let answer = S.substring(0, i) + T + S.substring(parseInt(i) + T.length);
            answer = answer.replace(/\?/g, "a");
            console.log(answer);
            return;
        }
    }

    console.log("UNRESTORABLE");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


'use strict'

function main(input){
  const lines = input.split('\n');
  const S = lines[0];
  const T = lines[1];

  let tIndex = undefined;
  for(let i=0;i<S.length-T.length+1;i++){
    let same_count=0;
    for(let j=0;j<T.length;j++){
      let partS = S.slice(i,i+T.length).split('');
      let partT = T.split('');
      if(partS[j]=='?' || partS[j]==partT[j]){
        same_count++;
      }
    }
    if(same_count==T.length){tIndex=i;}
  }

//  console.log(tIndex);

  if(tIndex+T.length>S.length || tIndex==undefined){
    console.log('UNRESTORABLE');
    return;
  }

  let result =[];

  for(let i =0;i<S.length;i++){
    if(i>=tIndex){
      result.push(T[i-tIndex]);
    }else{
      if(S[i]=='?'){
        result.push('a');
      }else{
        result.push(S[i]);
      }
    }
  }
  console.log(result.join(''));
}

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


"use strict"

function main(input) {
  input = input.split(/\n/)
  let S = input[0].split("")
  const T = input[1].split("")

  if (S.length < T.length) {
    console.log(ans)
    return
  } else {
    for (let i = S.length - T.length; i >= 0; i--) {
      //
      let x = 0
      for (let j = 0; j < T.length; j++) {
        //Tの区間の中で合致するかどうか
        if (S[i + j] == T[j] || S[i + j] == "?") {
          //この文字は合致、または?だからパス
        } else {
          //合致しない＞この区間は合致しない
          x++
          continue
        }
        //
      }
      if (x > 0) continue
      //continue されなかったので合致、Tで埋める
      // point = i
      //Tで埋める
      for (let k = 0; k < T.length; k++) {
        S[i + k] = T[k]
      }
      //残りの?をaに変換
      // S = S.replace(/(.+)/, "a")
      for (let i = 0; i < S.length; i++) {
        S[i] = S[i] == "?" ? "a" : S[i]
      }
      S = S.join("")

      console.log(S)
      return
    }
  }
  //
  console.log("UNRESTORABLE")
  //
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))


function Main(input) {
  input = input.split('\n');

  var h = parseInt(input[0].split(' ')[0], 10);
  var w = parseInt(input[0].split(' ')[1], 10);

  var s = [];
  for (var i = 0; i < h; i++) {
    s.push(input[1 + i].split(''));
  }

  var cnt = new Array(h).fill([]).map(() => new Array(w).fill(0));

  var dx = [-1, -1, -1, 0, 0, 1, 1, 1];
  var dy = [-1, 0, 1, -1, 1, -1, 0, 1];

  for (var i = 0; i < h; i++) {
    for (var j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        for (var k = 0; k < 8; k++) {
          var y = i + dy[k];
          var x = j + dx[k];
          if (!(0 <= y && y < h)) continue;
          if (!(0 <= x && x < w)) continue;
          cnt[y][x]++;
        }
      }
    }
  }

  for (var i = 0; i < h; i++) {
    for (var j = 0; j < w; j++) {
      if (s[i][j] == '#') cnt[i][j] = -1;
    }
  }

  for (var i = 0; i < h; i++) {
    console.log(cnt[i].map(v => v == -1 ? '#' : v).join(''));
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).

. stands for an empty square, and # stands for a square containing a bomb.

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.

Print the strings after the process.

Constraints

1 \leq H,W \leq 50

S_i is a string of length W consisting of # and ..

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).

Sample Input 1

3 5
.....
.#.#.
.....

Sample Output 1

11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.

Sample Input 2

3 5
#####
#####
#####

Sample Output 2

#####
#####
#####

It is possible that there is no empty square.

Sample Input 3

6 6
#####.
#.#.##
####.#
.#..#.
#.##..
#.#...

Sample Output 3

#####3
#8#7##
####5#
4#65#2
#5##21
#4#310


"use strict";

var main = function main(input) {
  var args = input.split('\n');
  var H = parseInt(args[0].split(' ')[0], 10);
  var W = parseInt(args[0].split(' ')[1], 10);
  var S = [];

  for (var i = 0; i < H; i++) {
    S.push(args[i + 1]);
  }

  var result = Array.from(new Array(H), function () {
    return new Array(W).fill(0);
  });

  for (var _i = 0; _i < S.length; _i++) {
    var line = S[_i];

    for (var j = 0; j < line.length; j++) {
      if (line.charAt(j) == '#') {
        result[_i][j] = '#'; // 上に波及、一番上の時(i == 0)はやらない

        if (_i != 0) {
          var up = S[_i - 1]; // 左に波及、一番左の時(j == 0)はやらない

          if (j != 0) {
            if (up.charAt(j - 1) != '#') {
              result[_i - 1][j - 1]++;
            }
          } // 右に波及、一番右の時(j == W - 1)はやらない

          if (j != W - 1) {
            if (up.charAt(j + 1) != '#') {
              result[_i - 1][j + 1]++;
            }
          } // 真ん中に波及

          if (up.charAt(j) != '#') {
            result[_i - 1][j]++;
          }
        } // 下に波及、一番下の時(i == H - 1)はやらない

        if (_i != H - 1) {
          var down = S[_i + 1]; // 左に波及、一番左の時(j == 0)はやらない

          if (j != 0) {
            if (down.charAt(j - 1) != '#') {
              result[_i + 1][j - 1]++;
            }
          } // 右に波及、一番右の時(j == W - 1)はやらない

          if (j != W - 1) {
            if (down.charAt(j + 1) != '#') {
              result[_i + 1][j + 1]++;
            }
          } // 真ん中に波及

          if (down.charAt(j) != '#') {
            result[_i + 1][j]++;
          }
        } // 左右に波及
        // 左に波及、一番左の時(j == 0)はやらない

        if (j != 0) {
          if (line.charAt(j - 1) != '#') {
            result[_i][j - 1]++;
          }
        } // 右に波及、一番右の時(j == W - 1)はやらない

        if (j != W - 1) {
          if (line.charAt(j + 1) != '#') {
            result[_i][j + 1]++;
          }
        }
      }
    }
  }

  result.forEach(function (elem) {
    return console.log(elem.join(''));
  });
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));


"use strict"
process.stdin.resume();
process.stdin.setEncoding('utf8');
var input_string = '';

process.stdin.on('data', function (chunk) {
    input_string += chunk;
});
const space_input = function (line) {
    var arr = line.replace(/(^\s+)|(\s+$)/g, "").split(" ");
    for (var i = 0; i < arr.length; ++i) {
        arr[i] = +arr[i];
    }
    return arr;
};
const space_input_char = function (line) {
    var arr = line.replace(/(^\s+)|(\s+$)/g, "").split(" ");
    for (var i = 0; i < arr.length; ++i) {
        arr[i] = arr[i];
    }
    return arr;
};

process.stdin.on('end', function () {
    const lines = input_string.split('\n');
    const wh = space_input(lines[0])
    const H = wh[0]
    const W = wh[1]
    const t = lines.slice(1).filter(v=>v.length>0).map(l=>l.split(""))
    let res = []
    let mawari = []
    for(let i=-1;i<=1;++i){
        for(let j=-1;j<=1;++j){
            if(i!=0||j!=0){
                mawari.push([i,j])
            }
        }
    }
   // console.log(t)
    for(let h=0;h<H;++h){
        for(let w=0;w<W;++w){
            //console.log(h,w)
            if(t[h][w]==="."){
                let cnt=0
                for(let m of mawari){
                    //console.log(h+m[0])
                    if((h+m[0])<H&&0<=h+m[0] && ((w+m[1])<W)&&0<=w+m[1]){
                        if(t[h+m[0]][w+m[1]]==="#"){
                            cnt++
                        }
                    }
                }
                t[h][w]=cnt
            }
        }
        console.log(t[h].join(""))
    }

});


process.stdin.resume();
process.stdin.setEncoding('utf8');
var input_string = '';

process.stdin.on('data', function (chunk) {
    input_string += chunk;
});
const space_input = function (line) {
    var arr = line.replace(/(^\s+)|(\s+$)/g, "").split(" ");
    for (var i = 0; i < arr.length; ++i) {
        arr[i] = +arr[i];
    }
    return arr;
};
const space_input_char = function (line) {
    var arr = line.replace(/(^\s+)|(\s+$)/g, "").split(" ");
    for (var i = 0; i < arr.length; ++i) {
        arr[i] = arr[i];
    }
    return arr;
};

process.stdin.on('end', function () {
    const lines = input_string.split('\n');
    const wh = space_input(lines[0])
    const W = wh[0]
    const H = wh[1]
    const t = lines.slice(1).filter(v=>v.length>0).map(l=>l.split(""))
    let res = []
    let mawari = []
    for(let i=-1;i<=1;++i){
        for(let j=-1;j<=1;++j){
            if(i!=0||j!=0){
                mawari.push([i,j])
            }
        }
    }
    //console.log(mawari)
    for(let h=0;h<H;++h){
        for(let w=0;w<W;++w){
            if(t[h][w]==="."){
                let cnt=0
                for(let m of mawari){
                    //console.log(h+m[0])
                    if((h+m[0])<H&&0<=h+m[0] && ((w+m[1])<W)&&0<=w+m[1]){
                        if(t[h+m[0]][w+m[1]]==="#"){
                            cnt++
                        }
                    }
                }
                t[h][w]=cnt
            }
        }
        console.log(t[h].join(""))
    }

});


function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var N = parseInt(input[0]);
  var output = 0;
  for(var i = 1; i <= N; i++){
    var l = input[i].split(" ")[0];
    var r = input[i].split(" ")[1];
    output += (r - l) + 1;
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Score : 200 points

Problem Statement

Joisino is working as a receptionist at a theater.

The theater has 100000 seats, numbered from 1 to 100000.

According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).

How many people are sitting at the theater now?

Constraints

1≤N≤1000

1≤l_i≤r_i≤100000

No seat is occupied by more than one person.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
l_1 r_1
:
l_N r_N

Output

Print the number of people sitting at the theater.

Sample Input 1

1
24 30

Sample Output 1

7

There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30.

Sample Input 2

2
6 8
3 3

Sample Output 2

4


"use strict";

const main = arg => {
    const N  = arg.split("\n")[0];
    arg = arg.split("\n");
    arg.splice(0, 1);
    const lr = arg;
    let answer = 0;

    for(let i in lr) {
        answer += parseInt(lr[i].split(" ")[1]) - parseInt(lr[i].split(" ")[0]) + 1;
    }

    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {
    var input = input.split('\n');
    var n = parseInt(input[0], 10);
    var sum = 0;
    for(i = 1; i <= n; i++) {
      var a = input[i].split(' ').map(n => parseInt(n, 10));
      sum += a[1] - a[0] + 1;
    }
    console.log(sum);
 }
  Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {
    input = input.split('\n');
    input = input.map(function(e) {
        return e.split(' ').map(function(e) {
            return parseInt(e, 10);
        });
    });
    var r = 0;
    for (var i = 1; i < input.length-1; i++) {
        r += (input[i][1] - input[i][0] + 1);
    }

    console.log('%d', r);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    input = input.split('\n');
    input.shift();
    input = input.map(function(e) {
        return e.split(' ').map(function(e) {
            return parseInt(e, 10);
        });
    });
    var r = 0;
    for (var i = 0; i < input.length; i++) {
        r += (input[i][1] - input[i][0] + 1);
    }

    console.log('%d', r);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  var s = new Set(input.split("\n")[0]);
  for (var i = "a".charCodeAt(0); i <= "z".charCodeAt(0);i++) {
    if(!s.has(String.fromCharCode(i))) {
      console.log(String.fromCharCode(i));
      return;
    }
  }
  console.log("None");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Constraints

1 \leq |S| \leq 10^5 (|S| is the length of string S.)

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the lexicographically smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Sample Input 1

atcoderregularcontest

Sample Output 1

b

The string atcoderregularcontest contains a, but does not contain b.

Sample Input 2

abcdefghijklmnopqrstuvwxyz

Sample Output 2

None

This string contains every lowercase English letter.

Sample Input 3

fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg

Sample Output 3

d


function main(input) {
  input=input.trim();
  var s=input
  var all=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
  for(var i=0; i<s.length; i++){
    var temp=s.substr(i,1)
    //console.log(all.indexOf(temp));
    all.splice(all.indexOf(temp),1)
    //console.log(all);
  }
  //console.log(all);
  console.log(all[0]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(s) {
	s = s.split("\n")[0];
	var h = new Set();
	for (var i = 97; i <= 97+25; i++) {
		h.add(String.fromCharCode(i));
	}
	for (var i = 0; i < s.length; i++) {
		if (h.has(s[i])) {h.delete(s[i]);}
	}
	console.log(h.size === 0 ? "None" : Array.from(h).sort()[0]);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input){
  input = input.split("\n");
   var arr = input[1].split(" ").map(Number);
  var t = 0;
  var f = 0;
  arr.forEach(function(val){
    if(val%4==0)f++;
    else if(val%2==0)t++;
  });
  t-=2;
  t = Math.max(t,0)
  var n = arr.length;
  console.log(f*3+t>=n?"Yes":"No")
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Score : 400 points

Problem Statement

We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

It is impossible to permute a so that the condition is satisfied.

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const A = parseInt(arg[0].split(" ")[1]);
    const B = parseInt(arg[0].split(" ")[2]);

    let answer = (N - 2) * (B - A) + 1;

    if(A > B) {
        answer = 0;
    } else if(N === 1) {
        answer = A === B ? 1 : 0;
    }

    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1


'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');
    main();
});

function readline() {
    return inputString[currentLine++];
}

// main function .... code start ... ///
function main() {

//var input = readline()

var k = readline().split(' ').map(x => parseInt(x));
var n = k[0], a = k[1], b = k[2];

var ok = 0;
if(n == 1){
    if(a == b)
        ok = 1;
    else
        ok = 0;
}
else if(n > 1){
    if(a > b)
        ok = 0;
    else{
        ok = (b - a)*(n - 2) + 1;
    }
}

console.log(Math.max(ok , 0));

//

}


'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');
    main();
});

function readline() {
    return inputString[currentLine++];
}

// main function .... code start ... ///
function main() {

//var input = readline()

var k = readline().split(' ').map(x => parseInt(x));
var n = k[0], a = k[1], b = k[2];

// if(a > b){
//     ok = 0;
// }
// else if(n == 1){
//     if(a != b)
//         ok = 0;
//     else{
//         ok = 1;
//     }
// }
// else ok = (b-a) * (n-2) + 1;

console.log(Math.max((n-2) * (b-a) + 1, 0));

}

//


module.exports=function(e){var n={};function r(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)r.d(t,o,function(n){return e[n]}.bind(null,o));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=0)}([function(e,n,r){r(1)(r(2).readFileSync("/dev/stdin","UTF-8"))},function(e,n){function r(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var r=[],t=!0,o=!1,u=void 0;try{for(var i,l=e[Symbol.iterator]();!(t=(i=l.next()).done)&&(r.push(i.value),!n||r.length!==n);t=!0);}catch(e){o=!0,u=e}finally{try{t||null==l.return||l.return()}finally{if(o)throw u}}return r}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}e.exports=function(e){var n=r(e.split("\n")[0].split(" ").map(function(e){return Number(e)}),3),t=n[0],o=n[1],u=n[2];if(o>u)console.log(0);else if(o!=u)if(1!=t)if(2!=t){var i=(u-o)*(t-2)+1;console.log(i)}else console.log(1);else console.log(0);else console.log(1)}},function(e,n){e.exports=require("fs")}]);


main = function(input) {
    var data = input.split("\n").join(" ").split(" ");
    var n = parseInt(data[0]);
    var a = parseInt(data[1]);
    var b = parseInt(data[2]);

    var ans = 0;

    if(n == 1){
        if(a == b)
            ans = 1;
        else
           ans = 0;
    }else if(n > 1){
         if(a > b)
             ans = 0;
        else{
            ans = (b - a)*(n - 2) + 1;
        }
    }

    ans = parseInt(ans);

    console.log(Math.max(parseInt(ans), parseInt(0)));
};

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


main = function(input) {
    var data = input.split("\n").join(" ").split(" ");
    var n = data[0];
    var a = data[1];
    var b = data[2];

    var ans = (n - 2) * (b - a) + 1;

    console.log(Math.max(parseInt(ans), parseInt(0)));
};

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


var input = require("fs").readFileSync("/dev/stdin", "utf8");
var data = input.split(' ');
var n=data[0];
var a=data[1];
var b=data[2];
/*
var pos = b-a+1
var nums = n-2

var fact = function(n){
	var p = 1;
  while(n>1) p *= n--;
  return p;
}

//console.log(n,a,b);
var sume = 0;
for(var i=1; i<=nums; i++ ){
	sume += fact(pos) / (fact(i) * fact(pos-i));
}
if( a>b )
	print(0)
else
	print(sume);**/

  console.log(a);


var data = readline().split(' ');
var n=data[0];
var a=data[1];
var b=data[2];
/*
var pos = b-a+1
var nums = n-2

var fact = function(n){
	var p = 1;
  while(n>1) p *= n--;
  return p;
}

//console.log(n,a,b);
var sume = 0;
for(var i=1; i<=nums; i++ ){
	sume += fact(pos) / (fact(i) * fact(pos-i));
}
if( a>b )
	print(0)
else
	print(sume);
  */

  print(a);


'use strict'

const main = (INPUT) => {
  const s = INPUT.split('\n')[0]
  console.log(s.lastIndexOf('Z') - s.indexOf('A') + 1)
}

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

Score : 200 points

Problem Statement

Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s).

Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z.

Constraints

1 ≦ |s| ≦ 200{,}000

s consists of uppercase English letters.

There exists a substring of s that starts with A and ends with Z.

Input

The input is given from Standard Input in the following format:

s

Output

Print the answer.

Sample Input 1

QWERTYASDFZXCV

Sample Output 1

5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

Sample Input 2

ZABCZ

Sample Output 2

4

Sample Input 3

HASFJGHOGAKZZFEGA

Sample Output 3

12


'use strict'

const calc = (arr, str) => {
  for (let i = 0;i < arr.length;i++) {
    if (arr[i] == str) return i;
  }
}

function main(arg) {
  arg = arg.split('');
  let gra = arg.slice();
  gra = gra.reverse();
  const a = calc(arg, 'A');
  const z = gra.length - calc(gra, 'Z');
  const str_length = z - a
  if (str_length > 0) {
    console.log(str_length)
  }
}

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


'use strict'

const main = input => {
	const s = input.trim()
	const md = s.match(/A.*Z/)
	if (md) console.log(md[0].length)
	else console.log(0)
}

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


'use strict'

const main = (input) => {
    const str = input.split('\n')[0]
    const strArr = str.split('')
    const strArrR = strArr.slice().reverse()
    const strLen = strArr.length

    const Aindex = strArr.indexOf('A')
    const Zindex = strLen - strArrR.indexOf('Z')
    console.log(Zindex - Aindex)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))


function main(input){
  var val = input.split(' ');
  var K = parseInt(val[0]);
  var S = parseInt(val[1]);
  var sum = 0;
  for(let i=0;i<=K;i++){
    for(let j=0;j<=K;j++){
      var value = S-(i+j);
      if(value >= 0 && value <= K){
        sum++;
        break;
      }
    }
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 200 points

Problem Statement

You are given two integers K and S.

Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.

How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?

Constraints

2≤K≤2500

0≤S≤3K

K and S are integers.

Input

The input is given from Standard Input in the following format:

K S

Output

Print the number of the triples of X, Y and Z that satisfy the condition.

Sample Input 1

2 2

Sample Output 1

6

There are six triples of X, Y and Z that satisfy the condition:

X = 0, Y = 0, Z = 2

X = 0, Y = 2, Z = 0

X = 2, Y = 0, Z = 0

X = 0, Y = 1, Z = 1

X = 1, Y = 0, Z = 1

X = 1, Y = 1, Z = 0

Sample Input 2

5 15

Sample Output 2

1

The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.


"use strict";

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

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

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

function main() {
    let k = next();
    let s = next();
    let ans = 0;
    let x, y, z
    for (x = 0; x <= k; x++)
        for (y = 0; y <= k; y++)
            if (x + y <= s && x + y + k >= s) {
                //console.log(x, y, s - x - y, k)
                ans ++
            }
    return ans;
}


// https://atcoder.jp/contests/abc051/tasks/abc051_b
"use strict";
function Main(input) {
  // const [K, S] = input.split(" ").map(Number);
  const params = input.split(" ").map(Number);
  const K = params[0];
  const S = params[1];

  let count = 0;
  for (let x = 0; x <= K; x++) {
    if (x > S) break;
    for (let y = 0; y <= K; y++) {
      if (x + y > S) break;
      for (let z = 0; z <= K; z++) {
        if (x + y + z > S) {
          break;
        }
        if (x + y + z === S) {
          count++;
          break;
        }
      }
    }
  }
  console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const K = parseInt(arg[0].split(" ")[0]);
    const S = parseInt(arg[0].split(" ")[1]);

    let answer = 0;

    for(let i=0; i<=K; i++) {
        for(let j=0; j<=K; j++) {
            let X = i;
            let Y = j;

            if(i + j > K) continue;

            if(K - (i+j) <= K) {
                // console.log("X:" + X);
                // console.log("Y:" + Y);

                answer++;
            }
        }
    }

    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
	var res = 0;
 	input = input.split(',');
  	const max = parseInt(input[0]);
  	const total = parseInt(input[1]);
	for (var X = 0;X <= max;X++) {
    	for (var Y = 0;Y <= max;Y++) {
            var Z = (total - parseInt(X) - parseInt(Y));
           	if (0 <= Z && Z <= max) {
              res++;
            }
        }
    }
	console.log(res);
}

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


function main(input) {
	var res = 0;
 	input = input.split(',');
  	const max = input[0];
  	const total = input[1];
	for (var X = 0;X <= max;X++) {
    	for (var Y = 0;Y <= max;Y++) {
        	for(var Z = 0;Z <= max;Z++) {
            	var a = X + Y + Z;
            	if (a == total) res++;
            }
        }
    }
	console.log(res);
}

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


function Main(input) {
	  var inputs = input.split(' ');
	  var K = Number(inputs[0]);
	  var S = Number(inputs[1]);
	  var count = 0;
	  for(var X = 0; X <= K; X++) {
	    for(var Y = 0; Y <= K; Y++) {
	      var Z = (S - X - Y);
	      if(0 <= Z && Z <= K) {
	        count++;
	      }
	    }
	  }
	  console.log(count);
	}

	Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  var inputs = input.split(' ');
  var K = Number(inputs[0]);
  var S = Number(inputs[1]);
  var count = 0;
  for(var X = 0; X <= K; X++) {
    for(var Y = 0; Y <= K; Y++) {
      for(var Z = 0; Z <= K; Z++) {
        if (X + Y + Z === S) {
          count++;
        }
      }
    }
  }
  console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.split(" ");
	//input = input.split("\n");
	input = input.split(" ").map((a)=>Number(a));
	//input = input.split("\n").map((a)=>Number(a));
  var K = input[0];
  var S = input[1];
  var output = 0;
  for(var i = 0; i <= K; i++){
    for(var j = 0; j <= K; j++){
      for(var l = 0; l <= K; l++){
        if(i + j + l == S){
           output++;
           }
      }
    }
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


'use strict'

function main(input) {
  input = input
    .trim()
    .split(' ')
    .map(Number)
  const k = input[0]
  const s = input[1]
  let count = 0
  for (let xi = 0; xi <= k; xi++) {
    for (let yi = 0; yi <= k; yi++) {
      for (let zi = 0; zi <= k; zi++) {
        if (xi + yi + zi === s) count++
      }
    }
  }

  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


"use strict";
const main = arg => {
  let K = arg.split(" ")[0];
  let S = arg.split(" ")[1];
  let cnt = 0;
  for(let x = 0; x <= K; x++){
    for(let y = 0; y <= K; y++){
      for(let z = 0; z <= K; z++){
        if(x + y + z == S){
        	cnt++;
        }
      }
    }
  }
  console.log(cnt);
}

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


function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var K = parseInt(line[0]);
    var S = parseInt(line[1]);
    var roop = Math.min(K,S);
    var ans =0;
    for(var A=0;A<=roop;A++){
        if(S-K-A>=0){
            if(2*K-S+A+1>0){
                ans += 2*K-S+A+1;
            }
        }
        else if(S-K-A<0){
            if(S-A+1>0){
                ans += S-A+1;
            }
        }
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function combination(input) {
	var max = input.split(" ")[0];
	var sum = input.split(" ")[1];
	var count = 0;
	if(sum <= max){
		for(var x = 0; x < sum+1; x++){
			for(var y = 0; y < sum+1-x; y++){
				for(var z = 0; z < sum+1-x-y; z++){
					if(z===sum-x-y){
						count++;
					}
				}
			}
		}
	} else if (sum > max){
		for(var x = 0; x < max+1; x++){
			if(sum-x <= max){
				for(var y = 0; y < sum+1-x; y++){
					for(var z = 0; z < sum+1-x-y; z++){
						if(z===sum-x-y){
							count++;
						}
					}
				}
			}else if(sum-x > max){
				for(var y = 0; y < max+1; y++){
					if(sum-x-y <= max){
						for(var z = 0; z < sum+1-x-y; z++){
							if(z===sum-x-y){
								count++;
							}
						}
					}else if(sum-x-y > max){

					}
				}
			}
		}
	}
	console.log(count);
}

combination(require("fs").readFileSync("/dev/stdin", "utf8"));


// inputに入力データ全体が入る
function Main(input) {
	input = input.split(" ");
	var locale = Number(input[0]);
	var sum = Number(input[1]);
	var result = 0;
    if (locale * 3 === sum){
	    result++;
	} else {
	    for (var i = 0; i <= locale; i++) {
	        for (var j = 0; j <= locale; j++) {
	            if (i + j > sum) {

	            } else {
	                result++;
	            }
	        }
	    }
	}
	console.log(result);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function spilitInput(input) {
  var splited = [];
  var rows = input.split('\n');
  for (var i = 0; i < rows.length; i += 1) {
    splited.push(rows[i].split(' '));
  }
  return splited;
}
function Main(input) {
  var splited = spilitInput(input);
  var S = splited[0][0];
  var ys = ['erase', 'dream', 'eraser', 'dreamer'];

while (S.length > 0) {
  var match = false;
  for (var i = 0; i < ys.length && !match; i += 1) {
    var word = ys[i];
    if (S.slice(-1 * word.length) == word) {
        match = true;
        S = S.slice(0, (S.length - word.length));
    }
  }
  if (!match) {
    break;
  }
}

  if (S.length > 0) {
    console.log('NO');
  } else {
    console.log('YES');
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO


// https://atcoder.jp/contests/abc049/tasks/arc065_a

function main(arg) {
  const S = arg;

  const s = S.replace(/dream(er(aser?)?)?|eraser?/g, '');
  if (s == '') {
    console.log('YES');
  } else {
    console.log('NO');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
  const args = input.split('').reverse().join('');

  while(true){var rplc1 = /maerd/g;
  var rplc2 = /remaerd/g;
  var rplc3 = /esare/g;
  var rplc4 = /resare/g;
  var i = args.replace(rplc1,'');
  var j = i.replace(rplc2,'');
  var k = j.replace(rplc3,'');
  var l = k.replace(rplc4,'');
  var m = l === '';
  if(m){break;}
  }

  if(!m){
    console.log('NO');
  }else if(m){
    console.log('YES');
  }

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