'use strict';

function Main(input) {
    const tmp = input.trim().split('\n');
    const N = Number(tmp[0]);
    const S = tmp[1];
    // console.log(N, S);

    let result = 0;
    for (let i = 0; i < N; i++) {
        for (let j = 1; j < N; j++) {
            for (let k = 1; k < N; k++) {
                if (j === k) continue;
                if (i + j + k > N - 1) break;
                const check1 = [S[i], S[i + j], S[i + j + k]];
                // console.log(`check1${check1}`);
                if (check(check1)) {
                    result++;
                }
                const check2 = [S[i], S[i + k], S[i + j + k]];
                // console.log(`check2${check2}`)
                if (check(check2)) {
                    result++;
                }
            }
        }
    }
    console.log(result / 2);
}
function check(arr) {
    if (arr[0] !== arr[1] && arr[0] !== arr[2] && arr[1] !== arr[2]) {
        return true;
    }
    return false;
}

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

// Main(`4
// RRGB`);
// Main(`39
// RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB`);


'use strict'
const Main=input=>{
    input=input.split("\n");
    const num=parseInt(input[0]);
    const str=input[1];

    const count=0;

    for(let i=1;i<num+1;i++){
        for(let j=i+1;j<num+1;j++){
            for(let k=j+1;k<num+1;k++){
                if(k-j!=j-i){
                    if(str[i]!=str[j]||str[i]!=str[k]||str[j]!=str[k]){
                        count++;
                    }
                }
            }
        }
    }

    console.log(count);
}

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

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

Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800

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.


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

const gcdArr = function(arr) {
  let gcdres = gcd(arr[0], arr[1])
  for (let i=2; i<arr.length; i++) {
    gcdres = gcd(gcdres, arr[i])
  }
  return gcdres
}

function gcd_impl(n,m) {
        for( let i = 0; i < 10; ++i ) {
                let t = n - m;
                let q = m > t;
                n = q ? m : t;
                m = q ? t : m;
                if( m == 0 ) { return n; }
        }
        return gcd_impl( m, n % m );
}

function gcd( n, m ) {
        return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}

const Main = (p)=>{
	// 1行目がinput[0], 2行目がinput[1], …に入る
	p = p.split("\n");
	let N = parseInt(p[0])//p.split(" ").map(Number);
	let S = p[1].split("").map(e=>{
	    if(e=="R")return 1;
	    if(e=="G")return 2;
	    if(e=="B")return 4;
	});
	//console.log(S);return;

	//文字列から10進数に変換するときはparseIntを使います

	let s=0;
	for(let i=1;i<=N;i++){
	    for(let j=i+1;j<=N;j++){
    	    for(let k=j+1;k<=N;k++){
    	        if(S[i-1]+S[j-1]+S[k-1]==7){
    	            if(j-i!=k-j)
    	               s++;
    	        }
    	    }
    	}
	}
	console.log(s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


const main = stdin => {
  const [A, B, C] = stdin.trim().split(' ')
  console.log(C, A, B)
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))

Score : 100 points

Problem Statement

We have three boxes A, B, and C, each of which contains an integer.

Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.

We will now do the operations below in order. Find the content of each box afterward.

Swap the contents of the boxes A and B

Swap the contents of the boxes A and C

Constraints

1 \leq X,Y,Z \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z

Output

Print the integers contained in the boxes A, B, and C, in this order, with space in between.

Sample Input 1

1 2 3

Sample Output 1

3 1 2

After the contents of the boxes A and B are swapped, A, B, and C contain 2, 1, and 3, respectively.

Then, after the contents of A and C are swapped, A, B, and C contain 3, 1, and 2, respectively.

Sample Input 2

100 100 100

Sample Output 2

100 100 100

Sample Input 3

41 59 31

Sample Output 3

31 41 59


function main(input) {
  const inputs = input.split('\n')
  const [X, Y, Z] = inputs[0].split(' ')
  // console.log(X, Y, Z)

  console.log(Z, X, Y)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main (input) {
    var arr = input.split(' ');
    var ans = [];

    ans.push(arr[2], arr[0], arr[1]);

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

}

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


function Main(input){
  input = input.split("");
  var a = parseInt(input[0],10);
  var b = parseInt(input[2],10);
  var c = parseInt(input[4],10);
  a = parseInt(input[2],10);
  b = parseInt(input[0],10);
  a = parseInt(input[4],10);
  c = parseInt(input[2],10);
  console.log('%d',a,b,c);

}

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


// ABC 161

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

  console.log(A + " " + B + " " + C)
}

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


// ABC 161
function Main(input) {
  input = input.split(" ");
  var A = parseInt(input[2],10);
  var B = parseInt(input[0],10);
  var C = parseInt(input[1],10);
  console.log(A + " " + B + " " + C)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


// ABC 161
function Main(input) {
  input = input.split(" ");
  let A = parseInt(input[2],10);
  let B = parseInt(input[0],10);
  let C = parseInt(input[1],10);
  console.log(A + " " + B + " " + C)
}

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


// ABC 161
Main("1 2 3")
function Main(input) {
  input = input.split(" ");
  let A = parseInt(input[2],10);
  let B = parseInt(input[0],10);
  let C = parseInt(input[1],10);
  console.log(A + " " + B + " " + C)
}

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


var obj = init();
Main();
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 next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
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 = nextIntArray();
  myout(one[2] + " " + one[0] + " " + one[1]);
}


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


"use strict"
// input data
function main(input) {
    const a = Number(input.split('\n')[0].split(' ')[0]);
    const b = Number(input.split('\n')[0].split(' ')[1]);
    const c = Number(input.split('\n')[0].split(' ')[2]);
    console.log(c + ' ' + a + ' ' + b);
}

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


function Main(arg) {
    arg = arg.trim().split(' ');
    console.log(`${arg[2]} ${arg[0]} ${arg[1]}`);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
	var tmp = input.split(" ");
    var a = parseInt(tmp[0],10);
    var b = parseInt(tmp[1],10);
    var c = parseInt(tmp[2],10);

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


function Main(input) {
	var tmp = input.split(" ");
    var a = parseInt(tmp[0],10);
    var b = parseInt(tmp[1],10);
    var c = parseInt(tmp[1],10);

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


function Main(input) {
  var line = input.split(' ');
  var A = Number(line[0]);
  var B = Number(line[1]);
  var C = Number(line[2]);

  var swap = A;
  A = B;
  B = swap;
  swap = A;
  A = C;
  C = swap;
  console.log(`${A} ${B} ${C}`);
}

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


"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var processData = function processData(lines) {
  var t;

  var _lines$0$split = lines[0].split(' '),
      _lines$0$split2 = _slicedToArray(_lines$0$split, 3),
      a = _lines$0$split2[0],
      b = _lines$0$split2[1],
      c = _lines$0$split2[2];

  t = b;
  b = a;
  a = t;
  t = c;
  c = a;
  a = t;
  console.log(a, b, c);
};

var i = '';
process.stdin.on('data', function (c) {
  return i += c;
});
process.stdin.on('end', function () {
  var _require = require('os'),
      EOL = _require.EOL;

  var lines = i.split(EOL);
  /*your input text, split by lines*/

  processData(lines);
});


var numberA = X;
var numberB = Y;
var numberC = Z;
var stock = null;

function change1 ={
  stock = numberA;
  numberA = numberB;
  numberB = stock;
}
function change2 ={
  stock = numberA;
  numberA = numberC;
  numberC = stock;
}

document.write(numberA+' '+numberB+' '+numberC);


'use strict'
function main(inp) {
  inp = inp.trim().split(' ').map(x=>x*1);
  let ans = new Array(3);
  ans[0] = inp[2];
  ans[1] = inp[0];
  ans[2] = inp[1];

  console.log(`${ans[0]} ${ans[1]} ${ans[2]}`);
}

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


"use strict"
function main(arg) {
    var r = arg.trim().split("\n")[0].split(' ').map(Number)
    var ans = [r[2], r[0], r[1]]
    console.log(ans.join(' '))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


const input = require("fs").readFileSync("/dev/stdin", "utf8")
const lines = input.split('\n')
const [N, M] = lines[0].split(' ').map(Number)
const A = lines[1].split(' ').map(Number)

const sum = A.reduce((a, b) => a + b)

const div = sum / (M * 4)

let count = 0
A.forEach(a => {
  count += a > div ? 1 : 0
})

console.log(count >= M ? 'Yes' : 'No')

Score : 200 points

Problem Statement

We have held a popularity poll for N items on sale. Item i received A_i votes.

From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.

If M popular items can be selected, print Yes; otherwise, print No.

Constraints

1 \leq M \leq N \leq 100

1 \leq A_i \leq 1000

A_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_N

Output

If M popular items can be selected, print Yes; otherwise, print No.

Sample Input 1

4 1
5 4 2 1

Sample Output 1

Yes

There were 12 votes in total. The most popular item received 5 votes, and we can select it.

Sample Input 2

3 2
380 19 1

Sample Output 2

No

There were 400 votes in total. The second and third most popular items received less than \dfrac{1}{4\times 2} of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.

Sample Input 3

12 3
4 56 78 901 2 345 67 890 123 45 6 789

Sample Output 3

Yes


function Main(inputs) {
	const inputlines = inputs.split("\n");
  	const firstline = inputlines[0].split(" ");
  	const votevalues = inputlines[1].split(" ").map(x => parseInt(x, 10));
  	const standard = 1 / (4 * firstline[1]);
  	let yes = 0;

    let totalvotes  = function(arr) {
    	let sum = 0;
    	arr.forEach(function(elm) {
        	sum += elm;
    	});
    	return sum;
	};

  	const currentstandard = totalvotes(votevalues) * standard;

  	for (let i = 0; i < votevalues.length; i++){
      	if(votevalues[i] >= currentstandard){
          	yes++;
          	if(yes == firstline[1]){
              	console.log("Yes");
              	break;
            }
        }
    }
  	if(yes != firstline[1]){
        console.log("No");
    }
}

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


// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  var ans = "Yes";
  input = input.trim().split("\n");
  const [N, M] = input[0].split(" ").map((n) => parseInt(n));
  var a = input[1].split(" ").map((n) => parseInt(n));
  a.sort((a, b) => b - a);
  var top = a.slice(0, M);
  const lim = arrsum(a) / 4 / N;

  if (top[top.length - 1] < lim) {
    ans = "No";
  }

  function arrsum(arr) {
    return arr.reduce((c, a, i, self) => {
      return c + a;
    });
  }

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


"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const N = Number(input[0].split(" ")[0]);
    const M = Number(input[0].split(" ")[1]);
    const A = input[1].split(" ").map(n => Number(n));
    const total = A.reduce((acc, curr) => acc+curr)
    const thresh = 1*total / (4*M)
    A.sort((a,b) => b-a)
    if(A[M-1] >= thresh) console.log("Yes")
    else console.log("No")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const N = Number(input[0].split(" ")[0]);
    const M = Number(input[0].split(" ")[1]);
    const A = input[1].split(" ").map(n => Number(n));
    const total = A.reduce((acc, curr) => acc+curr)
    const thresh = total / (4*M)
    A.sort().reverse()
    for(let i = 0; i<M; i++){
        if(A[i] < thresh){
            console.log("No")
            return
        }
    }
    console.log("Yes")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


'use strict';
function main(input) {
  const a = input.trim().split('\n')[0].split(' ').map(x => Number(x));
  const b = input.trim().split('\n')[1].split(' ').map(x => Number(x)).sort(function (a, b) {
    return b - a;
  });
  let sum = 0;

  for (let i = 0; i < b.length; i ++) {
    sum += b[i];
  }

  if (b[(a[1] - 1)] < sum / 4 / (a[1] - 1)) {
    console.log('No');
  } else {
    console.log('Yes');
  }

}

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


'use strict';
function main(input) {
  const a = input.trim().split('\n')[0].split(' ').map(x => Number(x));
  const b = input.trim().split('\n')[1].split(' ').map(x => Number(x)).sort(function (a, b) {
    return b - a;
  });
  let sum = 0;

  for (let i = 0; i < b.length; i ++) {
    sum += b[i];
  }

  if (b[(a[1] - 1)] < sum / 4 / (a[1] - 1)) {
    console.log('No');
  } else {
    console.log('Yes');
  }

  console.log();
}

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


function main(input) {
  var inputArr = input.split(/\r?\n/).map(inp => inp.split(" "));
  var ranking = inputArr[1].map(vote => parseInt(vote)).sort().reverse();
  var m = inputArr[0][1]
  var idx = m - 1;
  var popular = ranking[idx];
  var totalVotes = ranking.reduce((total, vote) => total + vote);

 for(var i = 0; i < m; i++) {
 	if( ranking[i] < 1.0 * totalVotes / m * 4 ) {
    	return false;
    }
 }
  return true;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

const lines = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line)
});
reader.on('close', () => {
  const first = lines[0].split(' ');
  const second = lines[1].split(' ');
  const secondNumber = second.map( str => parseInt(str, 10));
  secondNumber.sort(compareFunc);
  if(secondNumber[Number(first[1])-1] < 1 / 4 * Number(first[1])){
    console.log('No')
  }else{
    console.log('Yes')
  }
});

function compareFunc(a, b) {
  return b - a;
}


// ABC 161
"use strict"

//inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  const N = parseInt(input[0].split(" ")[0],10); //要素数
  const M = parseInt(input[0].split(" ")[1],10); //人気商品の数
  let A = input[1].split(" "); //各商品の数
  const sum = total(A); //総投票数
  let result = "Yes";

  // 降順
  A.sort(
    function(a,b){
      return (a < b ? 1 : -1);
    }
  );

  // 総得票数の1/4M未満ならNo
  for(let i=0;i<M;i++) {
    if(parseInt(A[i],10) < parseInt(sum * (1/(4*M))),10)result = "No";
  };
  console.log(result);
}

function total(arr) {
  let sum = 0;
  for(let i=0;i<arr.length;i++) {
    sum += parseInt(arr[i],10);
  }
  return sum;
}

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


// ABC 161
"use strict"

//inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  const N = parseInt(input[0].split(" ")[0],10); //要素数
  const M = parseInt(input[0].split(" ")[1],10); //人気商品の数
  let A = input[1].split(" "); //各商品の数
  const sum = total(A); //総投票数
  let result = "Yes";

  // 降順
  A.sort(
    function(a,b){
      return (a < b ? 1 : -1);
    }
  );

  // 総得票数の1/4M未満ならNo
  for(let i=0;i<=M;i++) {
    if(A[i] < sum * (1/(4*M)))result = "No";
  };
  console.log(result);
}

function total(arr) {
  let sum = 0;
  for(let i=0;i<arr.length;i++) {
    sum += parseInt(arr[i],10);
  }
  return sum;
}

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


function main(input) {
  const [n, m] = input[0].split(' ').map((n) => parseInt(n));
  const A = input[1].split(' ').map((n) => parseInt(n));
  const A_sum = A.reduce((a, x) => a + x);
  const ans = A.filter((a) => a > A_sum / 4 / m).length >= m;
  console.log(ans ? 'Yes' : 'No');
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'));


'use strict'

const Main = input => {
  const row_list = input.split('\n');
  const row0_sp = row_list[0].split(' ');
  const items = row_list[1].split(' ').map(item => Number(item));
  const N = row0_sp[0]; const M = row0_sp[1];

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

  let sum = 0;
  for(let item of items) sum += item;

  const border = sum * (1 / (4 * M + 1));

  let canSelect = true;

  for(let i=0; i<M; i++) {
    if(items[i] < border) {
      canSelect = false;
      break;
    }
  }

  console.log(canSelect ? 'Yes' : 'No');
}

//Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
Main(`3 2
380 19 1`);


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

process.stdin.on('data', function (chunk) {
    input_string += chunk;
    var lines = input_string.split("\n");
    if (lines.length % 2 == 1) {
        const p = lines[lines.length-1].split(' ');
        const n = p[0];
        const m = p[1];
        const c = []
        c.push(lines[lines.length].split(' ').map(value => parseInt(value)));
        var x = 0;
        var y = 0;
        for (var j = 0; j < n; j++) {
            y += c[0][j];
        }
        for (var i = 0; i < n; i++) {
            if (c[0][i] > (y / (4 * m))) {
                x += 1;
            }
        }
        if (x >= m) {
            console.log("Yes");
        }else {
            console.log("No");
        }
    }
});


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

process.stdin.on('data', function (chunk) {
    input_string += chunk;
    var lines = input_string.split("\n");
    // const[n, m] = lines[0].split(' ');

    if (lines.length % 2 == 1) {
        const p = lines[0].split(' ');
        const n = p[0];
        const m = p[1];
        // console.log(n);
        // console.log(m);
        // console.log(p);
        const c = []
        c.push(lines[1].split(' ').map(value => parseInt(value)));
        var x = 0;
        var y = 0;
        for (var j = 0; j < n; j++) {
            y += c[0][j];
        }
        for (var i = 0; i < n; i++) {
            if (c[0][i] > (y / (4 * m))) {
                x += 1;
                if (x == m) {
                    console.log("Yes");
                }
            }
        }

        if (x < m) {
            console.log("No");
        }
    }
});


const main = (inputs) => {
  var array1 = inputs[0].split(" ");
  var array2 = inputs[1].split(" ");
  var N = array1[0];
  var M = array1[1];

  var sum = 0;
  array2.forEach((elm) => {
    sum += elm - 0;
  });

  var NGValue = sum / (4 * M);

  var sortArray = array2.filter(v => {
    return Number(v) >= Number(NGValue);
  });
  if (sortArray.length >= M && N > 0 && M > 0) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


"use strict"
function main(arg) {
    var m = arg.trim().split("\n")[0].split(' ').map(Number)[1]
    var ai = arg.trim().split("\n")[1].split(' ').map(Number).sort((a,b) => b - a)
    var sum = 0
    var sum_m = 0
    for (var i = m - 1; i < ai.length; i++) {
        sum_m += ai[i]
    }
    for (var i = 0; i < ai.length; i++) {
        sum += ai[i]
    }
    // console.log(sum)
    if (sum_m * (4 * m) < sum ) {
        console.log('No')
    } else {
        console.log('Yes')
    }

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


"use strict";
function main(input) {
  let kari = input[0].trim().split(" ").map(i => parseInt(i));
  const n = kari[0];
  const m = kari[1];
  let a = input[1].trim().split(" ").map(i => parseInt(i));

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

  let sum = 0;
  for(let i=0;i<n;i++){
    sum += a[i];
  }

  let judge = false;
  for(let i=0;i<m;i++){
    if((sum/(4*m)) > a[i]){
      judge = true;
    }
  }

  console.log(judge?"No":"Yes");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


function Main(input){
	input = input.split("\n");
	var mem = input[0].split(" ").map(Number);
	const arr = new Array(100).fill(0);
	var a = input[1].split(" ").map(Number).sort(function(a,b){return a-b;});
	var b = input[2].split(" ").map(Number).sort(function(a,b){return a-b;});
	var c = input[3].split(" ").map(Number).sort(function(a,b){return a-b;});
	var sum = 0;
	var num = 0;
	while(mem[0]!=0||mem[1]!=0){
		if(a[a.length-1]>b[b.length-1]&&a[a.length-1]>c[c.length-1]&&mem[0]){
			sum += a[a.length-1];
			a.pop();
			mem[0]--;
		}else if(c[c.length-1]>b[b.length-1]){
			sum += c[c.length-1];
			c.pop();
			num++;
		}else{
			sum += b[b.length-1];
			b.pop();
			mem[1]--;
		}
		if(mem[0]==0) a = arr;
		if(mem[1]==0) b = arr;
		if(c.length==0) c = arr;
		if(mem[0]+mem[1]==num) break;
	}
	console.log(sum);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74


'use strict';
function Main(inputs) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  const input = inputs.split("\n");
  const a = Number(input[0].split(' ')[0]);
  const b = Number(input[0].split(' ')[1]);
  const c = Number(input[0].split(' ')[2]);
  if (c - a - b > 0) {
    console.log('Yes');
  }else if (4 * a * b < (c - a - b) * (c - a - b)){
    console.log('Yes');
  }else{
    console.log('No');
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?

Constraints

1 \leq a, b, c \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a \ b \ c

Output

If \sqrt{a} + \sqrt{b} < \sqrt{c}, print Yes; otherwise, print No.

Sample Input 1

2 3 9

Sample Output 1

No

\sqrt{2} + \sqrt{3} < \sqrt{9} does not hold.

Sample Input 2

2 3 10

Sample Output 2

Yes

\sqrt{2} + \sqrt{3} < \sqrt{10} holds.


'use strict';
function Main(inputs) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  const input = inputs.split("\n");
  const a = Number(input[0].split(' ')[0]);
  const b = Number(input[0].split(' ')[1]);
  const c = Number(input[0].split(' ')[2]);
  if(Math.sqrt(a) + Math.sqrt(b) < Math.sqrt(c)){
    console.log('Yes');
  }else{
    console.log('No');
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'
function main(inp) {
  inp = inp.trim().split(' ').map(x => x*1);

  let ans = "No";
  if((Math.sqrt(inp[0]) + Math.sqrt(inp[1]))< Math.sqrt(inp[2])){
	ans = "Yes";
  }
  console.log(ans);
}

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


'use strict'
function main(inp) {
  inp = inp.trim().split(' ').map(x => x*1);

  let ans = "No";
  if(Math.sqrt(inp[0]) + Math.sqrt(inp[1]) < Math.sqrt(inp[2])){
	ans = "Yes";
  }
  console.log(ans);
}

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


'use strict';

function main(input) {
  const i = input.split(' ').map((x) => x | 0);

  const a = Math.sqrt(i[0]);
  const b = Math.sqrt(i[1]);
  const c = Math.sqrt(i[2]);

  const ans = a + b < c ? 'Yes' : 'No';
  console.log(ans);
}

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


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

  var a = BigInt(input[0]);
  var b = BigInt(input[1]);
  var c = BigInt(input[2], 10);

  var as = Math.pow(a, 1/2);
  var bs = Math.pow(b, 1/2);
  var cs = Math.pow(c, 1/2);

  console.log(as, bs ,cs);
  if((as + bs) < cs) {
    console.log("Yes")
  } else {
    console.log("No")
  }
}

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