"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
  // your code goes here
  let a = parseInt(readline())
let bags = readline().split(' ')
let odd = 0, type = 0;
bags.forEach(x => {
    if(parseInt(x)%2===1)
        odd++;
})
if(odd % 2 === 1)
    type = 1;
else {
    type = bags.length - odd;
}
print(type)

}

Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?

The first line contains the only integer n (1≤n≤100) — the number of cookie bags Anna and Maria have. The second line contains n integers ai (1≤ai≤100) — the number of cookies in the i-th bag.

Print in the only line the only number — the sought number of ways. If there are no such ways print 0.

In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5+3=8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2*9+99=117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var k = lines[1].split(' ');
    var even = 0;
    var odd = 0;
    for(var j = 0; j < n; j++){
        if(k[j] % 2 === 0){
            even++;
        }else{
            odd++;
        }
    }
    if(odd % 2 == 1){
        console.log(odd);
    }else{
        console.log(even);
    }
});


"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {

       let [n,m] = readline().split(" ").map(x=>+x);

         let matrix = [];
  for (let i = 0; i < m; i++) {
    matrix.push(
      readline()
        .split(" ")
        .map((x) => +x)
    );
  }

       studentsAndShoelaces(n,m,matrix);

}

let graph = {};
let counter = 0;

function studentsAndShoelaces(n, m, studentsConnections) {
  graph = {};
  counter = 0;
  for (let i = 0; i < m; i++) {
    const [a, b] = studentsConnections[i];

    graph[a] ? graph[a].push(b) : (graph[a] = [b]);

    graph[b] ? graph[b].push(a) : (graph[b] = [a]);
  }

  removeSingles();

  console.log(counter);
}

function removeSingles() {
  //   console.log(graph);

  let toRemoveNodes = [];
  for (const node in graph) {
    if (graph[node].length === 1) {
      toRemoveNodes.push(node);

      delete graph[node];
    }
  }

  if (toRemoveNodes.length) {
    for (const node in graph) {
      graph[node] = graph[node].filter((x) => toRemoveNodes.includes(`${x}`));
    }
    counter++;

    toRemoveNodes = [];

    removeSingles();
  } else {
    return;
  }
}

Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.Determine how many groups of students will be kicked out of the club.

The first line contains two integers n and m — the initial number of students and laces (). The students are numbered from 1 to n, and the laces are numbered from 1 to m. Next m lines each contain two integers a and b — the numbers of students tied by the i-th lace (1≤a,b≤n,a≠b). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.

Print the single number — the number of groups of students that will be kicked out from the club.

In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.

"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {

       let [n,m] = readline().split(" ").map(x=>+x);

         let matrix = [];
  for (let i = 0; i < m; i++) {
    matrix.push(
      readline()
        .split(" ")
        .map((x) => x)
    );
  }

       studentsAndShoelaces(n,m,matrix);

}
 let graph = {};
let counter = 0;

function studentsAndShoelaces(n, m, studentsConnections) {
  graph = {};
  counter = 0;

  for (let i = 0; i < m; i++) {
    const [a, b] = studentsConnections[i];

    graph[a] ? graph[a].push(b) : (graph[a] = [b]);

    graph[b] ? graph[b].push(a) : (graph[b] = [a]);
  }

  removeSingles();

  console.log(counter);
}

function removeSingles() {
  let toRemoveNodes = [];
  for (const node in graph) {
    if (graph[node].length === 1) {
      toRemoveNodes.push(node);

      delete graph[node];
    }
  }

  if (toRemoveNodes.length) {
    for (const node in graph) {
      graph[node] = graph[node].filter((x) => !toRemoveNodes.includes(x));
    }
    counter++;

    toRemoveNodes = [];

    removeSingles();
  } else {
    return;
  }
}


const rl = require('readline').createInterface( process.stdin, process.stdout );

rl.question( '', ans => {
    let arr;
    rl.on( 'line', line => {
        arr = line.split(" ");
        solve( arr );
        rl.close();
    } )
} )

function solve( arr ){
    let output = [];

    arr.map( (n, i) => {
        output[n-1] = i+1;
    } )

    console.log(output);
}

Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there.If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift.Now Petya wants to know for each friend i the number of a friend who has given him a gift.

The first line contains one integer n (1≤n≤100) — the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi — the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.

Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i.

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

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

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

// ********** Code Start **********

function main (){
  let n = readline()
  let friends = readline().split(" ").map(i => parseInt(i))
  let answer = new Array(n)
  for (let i = 0; i < n; i++) {
    answer[friends[i]-1] = i+1
  }
  answer = answer.join(" ")
  print(answer)
}


let i = '';

process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const { EOL } = require('os');

    // program starts here
    const lines = i.split(EOL);

    // get the numbers, sort the numbers, use reduce to count duplicates
    let dupes = 0;
    lines[1].split(" ").sort().reduce((a, b) => {
        dupes += a === b;
        return b;
    }, undefined);
    console.log(dupes);
})

"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1,a2,...,an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).

The first line of the input data contains an integer n (1≤n≤5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1≤ai≤5000,1≤i≤n).

Print the only number — the minimum number of changes needed to get the permutation.

The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2.

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

//Don't have to see. end------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray(N);
	var count = new Array(5001).fill(0);
	for(var i = 0; i < N; i++){
		count[list[i]]++;
	}
	var output = 0;
	for(var i = 1; i <= N; i++){
		if(count[i] == 0){
			output++;
		}
	}
	myout(output);
}


"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

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

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

// ********** Code Start **********

function main (){
  let n = parseInt(readline())
  let soldiers = readline().split(" ").map(height => parseInt(height))

  let maxIndex = 0;
  let minIndex = 0;
  let maxHeight = soldiers[0];
  let minHeight = soldiers[0];

  for (let i = 1; i < n; i++) {
    if (soldiers[i] >= maxHeight) {
      maxHeight = soldiers[i];
      maxIndex = i;
    }

    if (soldiers[i] <= minHeight) {
      minHeight = soldiers[i];
      minIndex = i;
    }
  }

  let res = 0

  if (maxIndex < minIndex) res = (n-1) - minIndex + maxIndex
  if (maxIndex > minIndex) res = (n-1) - minIndex + maxIndex - 1

  print(res)

}

A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground.By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.

The first input line contains the only integer n (2≤n≤100) which represents the number of soldiers in the line. The second line contains integers a1,a2,...,an (1≤ai≤100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers a1,a2,...,an are not necessarily different.

Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

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

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

// ********** Code Start **********

function main (){
  let n = parseInt(readline())
  let soldiers = readline().split(" ").map(height => parseInt(height))

  let maxIndex = 0;
  let minIndex = 0;
  let maxHeight = soldiers[0];
  let minHeight = soldiers[0];

  for (let i = 1; i < n; i++) {
    if (soldiers[i] > maxHeight) {
      maxHeight = soldiers[i];
      maxIndex = i;
    }

    if (soldiers[i] <= minHeight) {
      minHeight = soldiers[i];
      minIndex = i;
    }
  }

  let res = 0

  if (maxIndex < minIndex) res = (n-1) - minIndex + maxIndex
  if (maxIndex > minIndex) res = (n-1) - minIndex + maxIndex - 1

  print(res)

}


"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
  // Number //
  // String //
  let temp = readline()
    .replace(/\r/g, "")
    .split(" ")
    .map((x) => parseInt(x));
  let n = temp[0];
  let m = temp[1];
  let array = [];
  for (let i = 0; i < n; i++) {
    let temp = readline()
      .replace(/\r/g, "")
      .split("")
      .map((x) => parseInt(x));
    array.push(temp);
  }
  let count = 0;
  let pointer = 0;
  let marked = [];
while (pointer < m) {
  let temp = [];
  for (let i = 0; i < n; i++) {
    temp.push(array[i][pointer]);
  }
  let best = temp.sort(function (a, b) {
    return a - b;
  })[temp.length - 1];
  for (let j = 0; j < temp.length; j++) {
    if (temp[j] == best) {
      let exit = marked.find((item) => item == j + 1);
      if (!exit) {
        marked.push(j + 1);
      }
    }
  }
  pointer++;
}
console.log(marked.length);
}

Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.Overall the group has n students. They received marks for m subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.Your task is to find the number of successful students in the group.

The first input line contains two integers n and m (1≤n,m≤100) — the number of students and the number of subjects, correspondingly. Next n lines each containing m characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.

Print the single number — the number of successful students in the given group.

In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject.

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

rl.on('line', (d) => {
  if (c === 0) {
    [n, m] = d.split(' ').map(Number);
    c++;
    return;
  }

  const marks = d;
  students.push(marks);
  c++;
});

rl.on('close', () => {
  const bests = new Set();
  for (let i = 0; i < students[0].length; i++) {
    let best = 0;
    for (let j = 0; j < students.length; j++) {
      if (students[j][i] > best) {
        best = students[j][i];
      }
    }

    for (let z = 0; z < students.length; z++) {
      if (students[z][i] === best) {
        bests.add(z);
      }
    }
  }

  console.log(bests.size);
});


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

let n = false;
readLine.on('line',
    (w) => {
        if (n === false){
            n = Number(w);
            return;
        }
        const input = w.split(' ')
        let actuacionSorprendente = 0
        let maxNum = input[0];
        let minNum = input[0];
        if (input.length > 1) {
        for (let i = 1; i < input.length; i++) {
            const element = Number(input[i]);
            if (element > maxNum) {
            maxNum = element;
            actuacionSorprendente++

            }
            if (element < minNum) {
                minNum = element;
                actuacionSorprendente++
            }
        }
        }
        console.log(actuacionSorprendente, maxNum, minNum );
    }
  );

Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.

The first line contains the single integer n (1≤n≤1000) — the number of contests where the coder participated.
The next line contains n space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.

Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.

In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing.

let fs = require("fs");

let txt = fs
  .readFileSync(0, "utf-8")
  .split(/[\n\r]/)
  .filter((data) => data.length > 0);
let arr = txt[1]
  .split(" ")
  .map((d) => d.trim())
  .filter((d) => d.length > 0)
  .map((d) => Number(d));

let min = arr[1];
let max = arr[1];
let amazing = 0;
arr.forEach((data) => {
  if (data > max) {
    max = data;
    ++amazing;
  } else if (data < min) {
    min = data;
    ++amazing;
  }
});

console.log(amazing);


After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1≤si≤4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

The first line contains integer n (1≤n≤10^5) — the number of groups of schoolchildren. The second line contains a sequence of integers s1,s2,...,sn (1≤si≤4). The integers are separated by a space, si is the number of children in the i-th group.

Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

In the first test we can sort the children into four cars like this:
  the third group (consisting of four children),  the fourth group (consisting of three children),  the fifth group (consisting of three children),  the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.

let input = "";
process.stdin.on("data", (data) => (input += data));
process.stdin.on("end", () => {
  let lines = input.split("\n");
  let n = lines.shift();
  let count = [0, 0, 0, 0, 0];
  lines
    .shift()
    .trim()
    .split(" ")
    .forEach((x) => count[x]++);
  let res = count[4];
  res += Math.floor(count[2] / 2);
  count[2] = count[2] % 2;
  let min13 = Math.min(count[1], count[3]);
  res += min13;
  count[1] -= min13;
  count[3] -= min13;
  if (count[2]) {
    count[1] -= Math.min(2, count[1]);
    res++;
  }
  res += Math.ceil(count[1] / 4);
  res += count[3];
  console.log(res);
});


let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var k = lines[1].split('').map(Number);
    var l = n;
    var a = 0;
    var b = 0;
    for(var j = 0; j < n; j++){
        if(k[j] >= k[l]){
            a++;
        }else if(k[j] < k[l]){
            b++;
        }
        l++;
    }
    if(a == n || b == n){
        console.log('YES');
    }else{
        console.log('NO');
    }
});

Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches the sum of digits in its second half.But of course, not every ticket can be lucky. Far from it! Moreover, sometimes one look at a ticket can be enough to say right away that the ticket is not lucky. So, let's consider the following unluckiness criterion that can definitely determine an unlucky ticket. We'll say that a ticket is definitely unlucky if each digit from the first half corresponds to some digit from the second half so that each digit from the first half is strictly less than the corresponding digit from the second one or each digit from the first half is strictly more than the corresponding digit from the second one. Each digit should be used exactly once in the comparisons. In other words, there is such bijective correspondence between the digits of the first and the second half of the ticket, that either each digit of the first half turns out strictly less than the corresponding digit of the second half or each digit of the first half turns out strictly more than the corresponding digit from the second half.For example, ticket 2421 meets the following unluckiness criterion and will not be considered lucky (the sought correspondence is 2>1 and 4>2), ticket 0135 also meets the criterion (the sought correspondence is 0<3 and 1<5), and ticket 3754 does not meet the criterion. You have a ticket in your hands, it contains 2n digits. Your task is to check whether it meets the unluckiness criterion.

The first line contains an integer n (1≤n≤100). The second line contains a string that consists of 2n digits and defines your ticket.

In the first line print "YES" if the ticket meets the unluckiness criterion. Otherwise, print "NO" (without the quotes).

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let n = parseInt(lines[0]);
  let num = lines[1].trim();
  let a = num
    .slice(0, n)
    .split("")
    .map((element) => parseInt(element))
    .sort((a, b) => a - b);
  let b = num
    .slice(n)
    .split("")
    .map((element) => parseInt(element))
    .sort((a, b) => a - b);
  let flag = true;
  if (a[0] > b[0]) {
    for (let i = 1; i < num.length / 2; i++) {
      if (a[i] <= b[i]) {
        flag = false;
        break;
      }
    }
  } else if (a[0] < b[0]) {
    for (let i = 0; i < num.length / 2; i++) {
      if (a[i] >= b[i]) {
        flag = false;
        break;
      }
    }
  } else {
    flag = false;
  }
  if (flag) {
    console.log("YES");
  } else {
    console.log("NO");
  }
});


Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa>pb, or pa=pb and ta<tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y+1, y+2, ..., y+x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y+x+1-th place.Your task is to count what number of teams from the given list shared the k-th place.

The first line contains two integers n and k (1≤k≤n≤50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1≤pi,ti≤50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces.

In the only line print the sought number of teams that got the k-th place in the final results' table.

The final results' table for the first sample is:
  1-3 places — 4 solved problems, the penalty time equals 10  4 place — 3 solved problems, the penalty time equals 20  5-6 places — 2 solved problems, the penalty time equals 1  7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.
The final table for the second sample is:
  1 place — 5 solved problems, the penalty time equals 3  2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let [n, k] = lines[0]
    .trim()
    .split(" ")
    .map((element) => parseInt(element));
  let teams = [];
  for (let i = 0; i < n; i++) {
    let [problems, time] = lines[i + 1]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    teams.push([problems, time]);
  }
  teams.sort((a, b) => {
    if (a[0] > b[0]) {
      return -1;
    } else if (a[0] < b[0]) {
      return 1;
    } else {
      if (a[1] < b[1]) {
        return -1;
      } else if (a[1] > b[1]) {
        return 1;
      } else {
        return 0;
      }
    }
  });
  let i = k - 1;
  let count = 0;
  while (i >= 0) {
    if (teams[i][0] === teams[k - 1][0] && teams[i][1] === teams[k - 1][1]) {
      count++;
      i--;
    } else {
      break;
    }
  }
  i = k;
  while (i < n) {
    if (teams[i][0] === teams[k - 1][0] && teams[i][1] === teams[k - 1][1]) {
      count++;
      i++;
    } else {
      break;
    }
  }
  console.log(count);
});


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

let firstNum, secondNum;
readline.on('line', function (line) {
    if (line !== "\n") {
        if (!firstNum) {
            firstNum = line;
        } else {
            secondNum = line;
            const num1 = firstNum.split("");
            const num2 = secondNum.split("");
            num2.sort((a, b) => b - a);

            for (let i = 0; i < num1.length; i++) {

                for (let j = i; j < num2.length; j++) {
                    if (num1[i] < num2[j]) {
                        num1[i] = num2[j];
                        num2.splice(j, 1);
                    }
                    else {
                        break;
                    }
                }
            }

            console.log(num1.join(""));

            process.exit();
        }
    }
});

You are given an integer a that consists of n digits. You are also given a sequence of digits s of length m. The digit in position j (1≤j≤m) of sequence s means that you can choose an arbitrary position i (1≤i≤n) in a and replace the digit in the chosen position i with sj. Each element in the sequence s can participate in no more than one replacing operation.Your task is to perform such sequence of replacements, that the given number a gets maximum value. You are allowed to use not all elements from s.

The first line contains positive integer a. Its length n is positive and doesn't exceed 10^5. The second line contains sequence of digits s. Its length m is positive and doesn't exceed 10^5. The digits in the sequence s are written consecutively without any separators.
The given number a doesn't contain leading zeroes.

Print the maximum value that can be obtained from a after a series of replacements. You are allowed to use not all elements from s. The printed number shouldn't contain any leading zeroes.

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

let firstNum, secondNum;
readline.on('line', function (line) {
    if (line !== "\n") {
        if (!firstNum) {
            firstNum = line;
        } else {
            secondNum = line;
            const num1 = firstNum.split("");
            const num2 = secondNum.split("");
            num2.sort((a, b) => b - a);
            let j = 0;
            for (let i = 0; i < num1.length; i++) {

                if (num1[i] < num2[j]) {
                    num1[i] = num2[j];
                    j++;
                }

                if(j > num2.length){
                    break;
                }
            }

            console.log(num1.join(""));

            process.exit();
        }
    }
});


let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL);
    solve(lines);
});

function solve(lines){

    const [ n, ...phoneNumbers ] = lines;
    let result = phoneNumbers[0].length;
    for(let i = 1; i < n-1; i++ ) {
        for(let j = 0; j <= result - 1; j++ ){
            if(phoneNumbers[i].charAt(j) !== phoneNumbers[i+1].charAt(j)) {
                result = j;
                break;
            }
        }
    }
    console.log(result);
}

Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1,s2,...,sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1≤i≤n). Help Polycarpus determine the length of the city phone code.

The first line of the input contains an integer n (2≤n≤3·10^4) — the number of Polycarpus's friends. The following n lines contain strings s1,s2,...,sn — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.

Print the number of digits in the city phone code.

A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789".

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

//Don't have to see. end------------------------------------------
function Main(){
	var N = nextInt();
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		list[i] = next();
	}
	for(var i = 0; i < list[0].length; i++){
		var s = list[0][i];
		for(var j = 0; j < N; j++){
			if(s != list[j][i]){
				myout(i);
				return;
			}
		}
	}
	myout(list[0].length);
}


let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var k = lines[1].split(' ').map(Number).sort(function(a, b){return a - b});
    var a = [];
    for(var j = 1; j <= n; j++){
        if(k[j] != k[j - 1]){
            a.push(k[j - 1]);
        }
    }
    if(n == 1){
        console.log('NO')
    }else{
    console.log(a[1])
    }
});

Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.

The first input line contains integer n (1≤n≤100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.

If the given sequence has the second order statistics, output this order statistics, otherwise output NO.

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var k = lines[1].split(' ').map(Number).sort(function(a, b){return a - b});
    var a = [];
    for(var j = 1; j <= n; j++){
        if(k[j] != k[j - 1]){
            a.push(k[j - 1]);
        }
    }
    if(a[1] === undefined){
        console.log('NO');
    }else{
        console.log(a[1]);
    }
});


const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split(/[\n\r]+/);
const log = (...args) => console.log(...args);

let count = 0;
const readnum = () => input[count++].trim().split(' ').map(a => +a);
const readword = () => input[count++].trim().split(' ');

let [N,M] = readnum();
let mat = [];
for (let i=0; i<N; i++)
  mat.push(readword().join());

console.log(solve(mat));

function solve(matrix) {
  let R = matrix.length, C = matrix[0].length;
  let res = 0;
  let cnt = Array(C).fill(0);

  for (let r=0; r<R; r++) {
    let row = matrix[r];
    for (let c=0; c<C; c++) {
      if (row[c] == '1') {
        cnt[c] = 0;
      } else {
          cnt[c] += 1;
  }
  }

    let stack = [-1];

    for (let i = 0; i < cnt.length; i++) {
      let cur = cnt[i];

      while (stack.length > 1 && cur < cnt[stack[stack.length-1]]) {
          let lastIdx = stack.pop(), lastCnt = cnt[lastIdx];

        res = Math.max(res, 2 * (lastCnt + (i - 1 - stack[stack.length-1])));
          }

          stack.push(i);
    }

    while (stack.length > 1) {
      let lastIdx = stack.pop(), lastCnt = cnt[lastIdx];

      res = Math.max(res, 2 * (lastCnt + (cnt.length - 1 - stack[stack.length-1])));
    }
  }

  return res;
};

Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n×m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that its sides are parallel to the office walls. Bob doesn't want to change or rearrange anything, that's why all the squares that will be occupied by the table should be initially free. Bob wants the new table to sit as many people as possible, thus its perimeter should be maximal. Help Bob find out the maximum possible perimeter of a bargaining table for his office.

The first line contains 2 space-separated numbers n and m (1≤n,m≤25) — the office room dimensions. Then there follow n lines with m characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.

Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.

'use strict';

function solve(n, m, a) {
  const h = new Array(m).fill(0);
  let res = 0;
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < m; j++) {
      if (a[i][j]) h[j] = 0;else h[j]++;
    }
    const stack = [];
    for (let j = 0; j <= m; j++) {
      while (stack.length && (j === m || h[stack[stack.length - 1]] > h[j])) {
        var _stack;
        const cur = stack.pop(),
              p = (_stack = stack[stack.length - 1]) !== null && _stack !== void 0 ? _stack : -1;
        if (h[cur]) res = Math.max(res, (j - p - 1) * 2 + h[cur] * 2);
      }
      stack.push(j);
    }
  }
  return res;
}

async function main(r) {
  const rns = async () => {
    return (await r()).split(' ').filter(s => s !== '').map(Number);
  };
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = await rns();
      const a = [];
      let tmp = n;
      while (tmp--) {
        a.push((await r()).split('').map(Number));
      }
      res[i] = solve(n, m, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});


const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split(/[\n\r]+/);
const log = (...args) => console.log(...args);

let count = 0;
const readnum = () => input[count++].trim().split(' ').map(a => +a);
const readword = () => input[count++].trim().split(' ');

let str = readword()[0];
console.log(solve(str));

function solve(str) {
  function f(str, par) {
    let cur = 0, bal = 0, max = 0;
    for (let ch of str) {
      cur++;

      if (ch == par) {
        bal++;
      } else {
        bal--;
      }

      if (bal == 0)
        max = Math.max(cur, max);

      if (bal < 0) {
        bal = 0;
        cur = 0;
      }
    }

    return max;
  }

  return Math.max(f(str, '('), f([...str].reverse().join(''), ')'));
}

A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?

Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 10^6.

Output the maximum possible length of a regular bracket sequence.

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

//Don't have to see. end------------------------------------------
function Main(){
	var s = next();
	var queue = [];
	var N = s.length;
	for(var i = 0; i < N; i++){
		if(s[i] == "("){
			queue.push("(");
		}else{
			if(queue.length > 0 && queue[queue.length - 1] == "("){
				queue.pop();
			}else{
				queue.push(")");
			}
		}
	}
	myout(N - queue.length);
}


"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
var word = readline()
var output

if (isNaN(Number(word))) {
    var wordLength = word.length
    if (wordLength >= 10) {
        output = `${word[0]}${wordLength - 2}${word[wordLength - 1]}`
    } else {
        output = word
    }
}
console.log(output)

}

In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.

The first line contains three integers n, m, k (1≤m≤n≤1000,0≤k≤10^6) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1≤r≤m) — index of the row, where belongs the corresponding tooth, and c (0≤c≤10^6) — its residual viability.
It's guaranteed that each tooth row has positive amount of teeth.

In the first line output the maximum amount of crucians that Valerie can consume for dinner.

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

const rl = readline.createInterface({ input, output });

let n, m, k, indicator = 0, row, health, sum = 0;
let myMap = new Map();

rl.on('line', (input) => {
    if (indicator == 0) {
        [n, m, k] = input.split(' ').map(item => parseInt(item));
        indicator++;
    }
    else {
        [row, health] = input.split(' ').map(item => parseInt(item));

        if (!myMap.has(row) || myMap.has(row) && myMap.get(row) > health)
            myMap.set(row, health);
    }

}).on('close', () => {

    for(let[key, value] of myMap)
    sum += value;

    console.log( (sum > k) ? k : sum);
});


var max=0;
var temp=0;
var arr = readline().split(' ');
var n=arr[0];
var l=arr[1];
var stripes=readline().split(' ');
var ans = [];
for (var i = 0; i < n; i++){
               if (max < stripes[i]){
                   max = stripes[i];}
}
                   for (var i = l; i <= max; i++)
                               {
                         for (var j = 0; j < n; j++)
                       {
                               temp += parseInt(stripes[j] / i);
                       }
                         ans.push(temp * i);
                         temp = 0;
                         }
       for (var i = 0; i < ans.lenght; i++)
           if (max < ans[i])
           max = ans[i];

           if (max > l)
           print(max);
           else
           print(0);

The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they may not have the same length (it is even possible for them to have different lengths)Every stripe can be cut into two or more parts. The cuttings are made perpendicularly to the side along which the length is measured. Thus the cuttings do not change the width of a stripe but each of the resulting pieces has a lesser length (the sum of which is equal to the length of the initial stripe)After all the cuttings the blinds are constructed through consecutive joining of several parts, similar in length, along sides, along which length is measured. Also, apart from the resulting pieces an initial stripe can be used as a blind if it hasn't been cut. It is forbidden to construct blinds in any other way.Thus, if the blinds consist of k pieces each d in length, then they are of form of a rectangle of k×d bourlemeters. Your task is to find for what window possessing the largest possible area the blinds can be made from the given stripes if on technical grounds it is forbidden to use pieces shorter than l bourlemeter. The window is of form of a rectangle with side lengths as positive integers.

The first output line contains two space-separated integers n and l (1≤n,l≤100). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated n integers ai. They are the lengths of initial stripes in bourlemeters (1≤ai≤100).

Print the single number — the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number 0.

In the first sample test the required window is 2×4 in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length of 4 cut in halves.

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

const rl = readline.createInterface({ input, output });

var cont = [], minLen,N = 0, woodCounter = 0, ans = 0, maxLen,helper = 0;

rl.on('line', (input) => {
    if(N === 0){
    cont = input.split(' ').map(item => parseInt(item));
    N = cont[0];
    minLen = cont[1];
    }
    else{
        cont =  input.split(' ').map(item => parseInt(item));
        maxLen = Math.max(...cont);

        for (let len = minLen; len <= maxLen; len++) {
            helper = 0;
            cont.forEach(item => {
                helper += parseInt(item / len);
            });
           if(ans < helper * len)
                ans = helper * len;

        }
        console.log(ans);
        rl.close();
    }

  });

  /*
N = 4  minLen = 2
1 2 3 4

  --
  --
  --
  --
  2*4 == 8

  ---
  ---

  2*3 == 6

  ----
  1*4 == 4

  */


const readline = require('readline');
const { stdin: input, stdout: output } = require('process');
const { parse } = require('path');

const rl = readline.createInterface({ input, output });

let i = 0, n = 0, myMap = new Map();

rl.on('line', (input) => {
   if (i == 0) {
      let arr = input.split(' ').map(it => parseInt(it));
      myMap.set('S', arr[0]);
      myMap.set('M', arr[1]);
      myMap.set('L', arr[2]);
      myMap.set('XL', arr[3]);
      myMap.set('XXL', arr[4]);
      i++;
   }
   else if (i == 1) {
      n = parseInt(input)
      i++;
   }
   else {
      switch (input) {
         case 'S':
            if (myMap.get('S') > 0) {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
            else if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('XL') - 1);
            }
            else {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            break;
         case 'M':
            if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('S') > 0) {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
            else if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('L') - 1);
            }
            else {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            break;
         case 'L':
            if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('XL') - 1);
            }
            else if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else if (myMap.get('XXL') > 0) {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            else {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
           break;
         case 'XL':
            if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('XL') - 1);
            }
            else if (myMap.get('XXL') > 0) {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            else if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
           break;
         default:
            if (myMap.get('XXL') > 0) {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            else if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('XL') - 1);
            }
            else if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
           break;

      }
   }

});

One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not exactly paper the walls with the oversupply). After considerable brain racking and some pre-estimating, the sponsor representatives ordered a certain number of T-shirts of sizes S, M, L, XL and XXL. The T-shirts turned out to bring good luck, that's why on the contest day there built up a line of K participants willing to get one. Every contestant is characterized by his/her desired T-shirt size (so it happens that for all the participants it is also one of the sizes S, M, L, XL and XXL). The participants come up to get a T-shirt one by one and try to choose the most suitable one, choosing it like this. If there is still a T-shirt of the optimal size left, that he/she takes it without further ado. Otherwise the contestant would prefer to choose a T-shirt with the size as close to the optimal one as possible (the distance between neighboring sizes is considered equal to one). If the variant of choice is not unique, the contestant will take a T-shirt of a bigger size (in case he/she grows more). For example, for a person whose optimal size is L the preference list looks like this: L, XL, M, XXL, S. Using the data on how many T-shirts of every size had been ordered by the organizers, on the size of contestants in the line determine who got a T-shirt of what size.

The first line contains five non-negative integers NS,NM,NL,NXL,NXXL not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer K (1≤K≤1000) which represents the number of participants. The next K lines contain the optimal T-shirt sizes for the contestants. The sizes are given in the order in which the participants stand in the line. It is guaranteed that NS+NM+NL+NXL+NXXL≥K.

For each contestant, print a line containing the size of the T-shirt he/she got.

const readline = require('readline');
const { stdin: input, stdout: output } = require('process');
const { parse } = require('path');

const rl = readline.createInterface({ input, output });

let i = 0, n = 0, myMap = new Map();

rl.on('line', (input) => {
   if (i == 0) {
      let arr = input.split(' ').map(it => parseInt(it));
      myMap.set('S', arr[0]);
      myMap.set('M', arr[1]);
      myMap.set('L', arr[2]);
      myMap.set('XL', arr[3]);
      myMap.set('XXL', arr[4]);
      i++;
   }
   else if (i == 1) {
      n = parseInt(input)
      i++;
   }
   else {
      switch (input) {
         case 'S':
            if (myMap.get('S') > 0) {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
            else if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('XL') - 1);
            }
            else {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            break;
         case 'M':
            if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('S') > 0) {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
            else if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('XL') - 1);
            }
            else {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            break;
         case 'L':
            if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('XL') - 1);
            }
            else if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else if (myMap.get('XXL') > 0) {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            else {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
           break;
         case 'XL':
            if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('XL') - 1);
            }
            else if (myMap.get('XXL') > 0) {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            else if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
           break;
         default:
            if (myMap.get('XXL') > 0) {
               console.log('XXL');
               myMap.set('XXL', myMap.get('XXL') - 1);
            }
            else if (myMap.get('XL') > 0) {
               console.log('XL');
               myMap.set('XL', myMap.get('XL') - 1);
            }
            else if (myMap.get('L') > 0) {
               console.log('L');
               myMap.set('L', myMap.get('L') - 1);
            }
            else if (myMap.get('M') > 0) {
               console.log('M');
               myMap.set('M', myMap.get('M') - 1);
            }
            else {
               console.log('S');
               myMap.set('S', myMap.get('S') - 1);
            }
           break;

      }
   }

});

[{'input': ['1 0 2 0 1\r\n3\r\nXL\r\nXXL\r\nM\r\n'], 'output': ['XXL\r\nL\r\nL\r\n']}, {'input': ['0 0 0 0 1\r\n1\r\nS\r\n'], 'output': ['XXL\r\n']}, {'input': ['1 0 1 0 1\r\n1\r\nS\r\n'], 'output': ['S\r\n']}, {'input': ['1 0 0 0 1\r\n2\r\nS\r\nL\r\n'], 'output': ['S\r\nXXL\r\n']}, {'input': ['1 1 1 1 1\r\n2\r\nXL\r\nM\r\n'], 'output': ['XL\r\nM\r\n']}, {'input': ['1 0 1 1 1\r\n3\r\nS\r\nXXL\r\nL\r\n'], 'output': ['S\r\nXXL\r\nL\r\n']}, {'input': ['1 0 2 1 1\r\n4\r\nS\r\nXXL\r\nL\r\nM\r\n'], 'output': ['S\r\nXXL\r\nL\r\nL\r\n']}, {'input': ['1 0 3 0 1\r\n5\r\nS\r\nS\r\nS\r\nXL\r\nL\r\n'], 'output': ['S\r\nL\r\nL\r\nXXL\r\nL\r\n']}, {'input': ['2 1 0 1 3\r\n4\r\nXL\r\nM\r\nS\r\nS\r\n'], 'output': ['XL\r\nM\r\nS\r\nS\r\n']}, {'input': ['2 2 0 2 1\r\n6\r\nS\r\nXXL\r\nM\r\nXL\r\nXXL\r\nXL\r\n'], 'output': ['S\r\nXXL\r\nM\r\nXL\r\nXL\r\nM\r\n']}, {'input': ['3 1 1 4 1\r\n10\r\nXL\r\nL\r\nL\r\nXXL\r\nXXL\r\nXL\r\nL\r\nXXL\r\nS\r\nM\r\n'], 'output': ['XL\r\nL\r\nXL\r\nXXL\r\nXL\r\nXL\r\nM\r\nS\r\nS\r\nS\r\n']}, {'input': ['14 3 1 0 2\r\n10\r\nS\r\nXL\r\nM\r\nXL\r\nS\r\nXXL\r\nL\r\nXXL\r\nS\r\nL\r\n'], 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\nL\r\nL\r\nXXL\r\nXL\r\nL\r\nXL\r\nM\r\nS\r\nM\r\nM\r\nXL\r\nXXL\r\nS\r\nXL\r\nXL\r\nM\r\nXL\r\nXXL\r\nXXL\r\nXL\r\nL\r\nS\r\nM\r\nXXL\r\nM\r\nL\r\nXXL\r\n'], 'output': ['XXL\r\nM\r\nXL\r\nS\r\nXXL\r\nS\r\nL\r\nXL\r\nXL\r\nXL\r\nXXL\r\nS\r\nXXL\r\nS\r\nXXL\r\nXL\r\nXL\r\nXXL\r\nXL\r\nXXL\r\nM\r\nS\r\nS\r\nS\r\nS\r\nXXL\r\nS\r\nL\r\nXL\r\nXXL\r\nXXL\r\nS\r\nXXL\r\nL\r\nXXL\r\nM\r\nS\r\nL\r\nL\r\nXL\r\nXL\r\nS\r\nXL\r\nL\r\nXL\r\nM\r\nXL\r\nL\r\nM\r\nS\r\nXL\r\nXXL\r\nXL\r\nL\r\nXL\r\nXL\r\nXL\r\nM\r\nM\r\nXL\r\nL\r\nS\r\nS\r\nXL\r\nS\r\nXXL\r\nXXL\r\nXL\r\nS\r\nXL\r\nXXL\r\nS\r\nS\r\nL\r\nL\r\nXXL\r\nXL\r\nL\r\nXL\r\nM\r\nS\r\nM\r\nM\r\nXL\r\nXXL\r\nS\r\nXL\r\nXL\r\nM\r\nXL\r\nXXL\r\nXXL\r\nXL\r\nL\r\nS\r\nM\r\nXXL\r\nM\r\nL\r\nXXL\r\n']}]


var getArr = function() {
	return readline().split(' ').map(function (a) {
		return parseInt(a);
	})
};

var getTree = function(arr, x, y, a, b) {
	var res = 0;
	for (var i = 0; i < a; i++) {
		for (var j = 0; j < b; j++) {
			res += arr[x + i][y + j];
		}
	}
	return res;
};

var data = [];
var input;

input = getArr();
var m = input[0];
var n = input[1];
for (var k = 0; k < m; k++) {
	data.push(getArr());
}
input = getArr();
var a = input[0];
var b = input[1];

var min = getTree(data, 0, 0, a, b);
for (var i = 0; i < m - a + 1; i++) {
	for (var j = 0; j < n - b + 1; j++) {
		min = Math.min(min, getTree(data, i, j, a, b));
	}
}

print(min);

Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the garden and guard the fruit because there’s no house in the garden! Vasya had been saving in for some time and finally he decided to build the house. The rest is simple: he should choose in which part of the garden to build the house. In the evening he sat at his table and drew the garden’s plan. On the plan the garden is represented as a rectangular checkered field n×m in size divided into squares whose side length is 1. In some squares Vasya marked the trees growing there (one shouldn’t plant the trees too close to each other that’s why one square contains no more than one tree). Vasya wants to find a rectangular land lot a×b squares in size to build a house on, at that the land lot border should go along the lines of the grid that separates the squares. All the trees that grow on the building lot will have to be chopped off. Vasya loves his garden very much, so help him choose the building land lot location so that the number of chopped trees would be as little as possible.

The first line contains two integers n and m (1≤n,m≤50) which represent the garden location. The next n lines contain m numbers 0 or 1, which describe the garden on the scheme. The zero means that a tree doesn’t grow on this square and the 1 means that there is a growing tree. The last line contains two integers a and b (1≤a,b≤50). Note that Vasya can choose for building an a×b rectangle as well a b×a one, i.e. the side of the lot with the length of a can be located as parallel to the garden side with the length of n, as well as parallel to the garden side with the length of m.

Print the minimum number of trees that needs to be chopped off to select a land lot a×b in size to build a house on. It is guaranteed that at least one lot location can always be found, i. e. either a≤n and b≤m, or a≤m и b≤n.

In the second example the upper left square is (1,1) and the lower right is (3,2).

const readline = require('readline');

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

var calculate = function (cont, row, col, a, b) {
    let ct = 0;
    for (let i = row; i < row + a; i++)
        for (let j = col; j < col + b; j++)
            ct += cont[i][j];
    return ct;
}

let n = -1, m = -1, cont = new Array(), a, b, i = 0, temp = new Array();
rl.on('line', (input) => {

    if (n === -1) {
        temp = input.split(' ').map(item => { return parseInt(item) });
        n = temp[0], m = temp[1];
    }
    else if (i++ < n) {
        cont.push(input.split(' ').map(item => { return parseInt(item) }));
    }
    else {
        temp = input.split(' ').map(item => { return parseInt(item) });
        a = temp[0], b = temp[1];
    }

}).on('close', () => {
    //console.log(cont);
    let ans = n * m, trees;
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {

            if (i + a <= n && j + b <= m) {
                trees = calculate(cont, i, j, a, b);
                if (ans > trees) ans = trees;
            }

            if (i + b <= n && j + a <= m) {
                trees = calculate(cont, i, j, b, a);
                if (ans > trees) ans = trees;
            }
        }
    }
    console.log(ans);
});


const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
let i = 0;
let orginal = [];
let swapped = [];
readline.on('line', line => {
  i++;
  if (i === 1) {
    orginal = [...Array(parseInt(line)).keys()];
    orginal.splice(0, 1);
  }
  else {
    readline.close();
    swapped = line.split(' ').map((x) => {
      return parseInt(x);
    });
    difference = orginal.reduce((list, coin, index) => {
      if (coin !== swapped[index]) {
        list.push(coin)
      }
      return list
    }, []);
    if (difference.length === 0) {
      console.log(0, 0)
    } else {
      const firstIndex = orginal.indexOf(difference[0]);
      const lastIndex = orginal.indexOf(difference[difference.length - 1]);
      const originalPart = orginal.slice(firstIndex, lastIndex + 1)
      const reversedPart = swapped.slice(firstIndex, lastIndex + 1);
      if (isEqual(originalPart, reversedPart.reverse())) {
        console.log(difference[0], difference[difference.length - 1])
      } else {
        console.log(0, 0)
      }
    }

  }
});

function isEqual(a, b)
{
  // if length is not equal
  if(a.length!=b.length)
   return false;
  else
  {
  // comapring each element of array
    return a.reduce((value, e, index) => {
      if (e === b[index]) {
        value = true
        return value
      }
      value = false
      return value
    }, false)
  }
}

Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order. That is, he took a certain segment [l,r] and reversed it. At that the segment's endpoints did not coincide. For example, if n=8, then initially Vasya's coins were kept in the order 1 2 3 4 5 6 7 8. If Vasya's younger brother chose the segment [2,6], then after the reversal the coin order will change to 1 6 5 4 3 2 7 8. Vasya suspects that someone else could have spoilt the permutation after his brother. Help him to find that out. Check if the given permutation can be obtained from the permutation 1 2 ... n using exactly one segment reversal. If it is possible, find the segment itself.

The first line contains an integer n (1≤n≤1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is used exactly 1 time.

If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1≤l<r≤n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one.

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
let i = 0;
let orginal = [];
let swapped = [];
readline.on('line', line => {
  i++;
  if (i === 1) {
    orginal = Array.from({length: parseInt(line) + 1}, (x, k) => k);
    orginal.splice(0, 1);
  }
  else {
    readline.close();
    swapped = line.split(' ').map((x) => {
      return parseInt(x);
    });
    difference = orginal.reduce((list, coin, index) => {
      if (coin !== swapped[index]) {
        list.push(coin)
      }
      return list
    }, []);
    if (difference.length === 0) {
      console.log(0, 0)
    } else {
      const firstIndex = orginal.indexOf(difference[0]);
      const lastIndex = orginal.indexOf(difference[difference.length - 1]);
      const originalPart = orginal.slice(firstIndex, lastIndex + 1)
      const reversedPart = swapped.slice(firstIndex, lastIndex + 1);
      if (isEqual(originalPart, reversedPart.reverse())) {
        console.log(difference[0], difference[difference.length - 1])
      } else {
        console.log(0, 0)
      }
    }

  }
});

function isEqual(a, b)
{
  // if length is not equal
  if(a.length!=b.length)
   return false;
  else
  {
  // comapring each element of array
    return a.reduce((value, e, index) => {
      if (e === b[index]) {
        value = true
        return value
      }
      value = false
      return value
    }, false)
  }
}


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

const rl = readline.createInterface({ input, output });

let n = -1, arr = [];

rl.on('line', (input) => {
    if (n == -1)
        n = parseInt(input);
    else {
        arr = input.split(' ').map(it => parseInt(it));
        let sum = 0, minOdd = 101;
        arr.forEach(lm => {
            if (lm % 2 != 0 && lm < minOdd)
                minOdd = lm;
            sum += lm;
        });
        if (n == 1 && sum % 2 != 0)
            console.log(sum);
        else if (n == 1)
            console.log(0);
        else if (sum % 2 == 0)
            console.log(sum - minOdd)
        else
            console.log(sum)

        rl.close()
    }
})

Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1,a2,... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet.

The first line contains an integer n (1≤n≤100), which is the number of flowers growing in the field. The second line contains n integers ai (1≤ai≤100) which represent the number of petals on a given i-th camomile.

Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower.

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

const rl = readline.createInterface({ input, output });

let n = -1, cont = []

rl.on('line', (input) => {
    if (n == -1)
        n = parseInt(input);

    else {
        cont = input.split(' ').map(it => parseInt(it));
        let minOdd = 101, sum = 0
        cont.forEach(it => {
            if (it % 2 != 0 && minOdd > it)
                minOdd = it
            sum += it
        });

        if (n == 1)
            console.log((sum % 2 != 0) ? sum : 0)
        else if (sum % 2 == 0 && minOdd != 101)
            console.log(sum - minOdd)
        else if (sum % 2 == 0)
            console.log(0)
        else
            console.log(sum)

        rl.close()
    }

});


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

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

  arr.push(d.split(' ').map(Number));

  c++;
});

rl.on('close', () => {
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr.length; j++) {
      ans += arr[i][j];
    }
  }

  if (arr.length > 3) {
    ans -= arr[0][1];
    ans -= arr[0][arr.length - 2];
    ans -= arr[arr.length - 1][1];
    ans -= arr[arr.length - 1][arr.length - 2];
    ans -= arr[1][0];
    ans -= arr[1][arr.length - 1];
    ans -= arr[arr.length - 2][0];
    ans -= arr[arr.length - 2][arr.length - 1];
  }

  console.log(ans);
});

The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:    Elements of the main diagonal.   Elements of the secondary diagonal.   Elements of the "middle" row — the row which has exactly  rows above it and the same number of rows below it.   Elements of the "middle" column — the column that has exactly  columns to the left of it and the same number of columns to the right of it.    The figure shows a 5 × 5 matrix.   The good elements are marked with green.  Help the Smart Beaver count the sum of good elements of the given matrix.

The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are:    1 ≤ n ≤ 5  The input limitations for getting 100 points are:   1 ≤ n ≤ 101

Print a single integer — the sum of good matrix elements.

NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.

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

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

  arr.push(d.split(' ').map(Number));

  c++;
});

rl.on('close', () => {
  let ans = 0;
  let n = arr.length;

  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr.length; j++) {
      if (i == j || i == Math.floor(n / 2) || j == Math.floor(n / 2) || i + j == n-1) {
        ans += arr[i][j];
      }
    }
  }

  console.log(ans);
});


const prompt = require('prompt-sync')();

function sort(members) {
    var rats = []
    var womanChildren = []
    var men = []
    var captain = []
    for (const member of members) {
        if (member.status == "rat")
            rats.push(member.name)
        if (member.status == "woman" || member.status == "child")
            womanChildren.push(member.name)
        if (member.status == "man")
            men.push(member.name)
        if (member.status == "captain")
            captain.push(member.name)
    }
    const out = [...rats, ...womanChildren, ...men, ...captain]
    return out
}

function sinking_ship() {
    var members = []
    var number = parseInt(prompt())
    for (let i = 0; i < number; i++) {
        const line = prompt()
        const words = line.split(" ")
        members.push({
            name: words[0],
            status: words[1]
        })
    }
    const result = sort(members)
    for (const res of result) {
        console.log(res);
    }
}

const final = sinking_ship()

The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.

The first line contains an integer n, which is the number of people in the crew (1≤n≤100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.

Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.

6
Jack captain
Alice woman
Charlie man
Teddy rat
Bob child
Julia woman

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

class Info {
    constructor(rowNum, name, identity) {
        this.rowNum = rowNum;
        this.name = name;
        this.identity = identity;
    }
};

let i = 0, cont = [];

rl.on('line', (input) => {
    if (i === 0)
        i++;
    else {
        let spaceInd = input.indexOf(' ');
        let name = input.substring(0, spaceInd);
        let identity = input.substring(spaceInd + 1);
        cont.push(new Info(i, name, identity));
        i++;
    }

}).on('close', () => {
    cont.sort((obj1, obj2) => {
        if (obj1.identity == 'rat' && obj2.identity != 'rat')
            return -1;

        if (obj1.identity != 'rat' && obj2.identity == 'rat')
            return 1;

        //woman and children
        if ((obj1.identity == 'woman' || obj1.identity == 'child') && (obj2.identity != 'woman' && obj2.identity != 'child'))
            return -1;

        if ((obj1.identity != 'woman' && obj1.identity != 'child') && (obj2.identity == 'woman' || obj2.identity == 'child'))
            return 1;

        if (obj1.identity == 'man' && obj2.identity != 'man')
            return -1;

        if (obj1.identity != 'man' && obj2.identity == 'man')
            return 1;

        return obj1.rowNums - obj2.rowNums;
    })

    for (let obj of cont) {
        console.log(obj.name);
    }

})

[{'input': ['6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n'], 'output': ['Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n']}, {'input': ['1\r\nA captain\r\n'], 'output': ['A\r\n']}, {'input': ['1\r\nAbcdefjhij captain\r\n'], 'output': ['Abcdefjhij\r\n']}, {'input': ['5\r\nA captain\r\nB man\r\nD woman\r\nC child\r\nE rat\r\n'], 'output': ['E\r\nD\r\nC\r\nB\r\nA\r\n']}, {'input': ['10\r\nCap captain\r\nD child\r\nC woman\r\nA woman\r\nE child\r\nMan man\r\nB child\r\nF woman\r\nRat rat\r\nRatt rat\r\n'], 'output': ['Rat\r\nRatt\r\nD\r\nC\r\nA\r\nE\r\nB\r\nF\r\nMan\r\nCap\r\n']}, {'input': ['5\r\nJoyxnkypf captain\r\nDxssgr woman\r\nKeojmnpd rat\r\nGdv man\r\nHnw man\r\n'], 'output': ['Keojmnpd\r\nDxssgr\r\nGdv\r\nHnw\r\nJoyxnkypf\r\n']}, {'input': ['11\r\nJue rat\r\nWyglbyphk rat\r\nGjlgu child\r\nGi man\r\nAttx rat\r\nTheorpkgx man\r\nYm rat\r\nX child\r\nB captain\r\nEnualf rat\r\nKktsgyuyv woman\r\n'], 'output': ['Jue\r\nWyglbyphk\r\nAttx\r\nYm\r\nEnualf\r\nGjlgu\r\nX\r\nKktsgyuyv\r\nGi\r\nTheorpkgx\r\nB\r\n']}, {'input': ['22\r\nWswwcvvm woman\r\nBtmfats rat\r\nI rat\r\nOcmtsnwx man\r\nUrcqv rat\r\nYghnogt woman\r\nWtyfc man\r\nWqle child\r\nUjfrelpu rat\r\nDstixj man\r\nAhksnio woman\r\nKhkvaap woman\r\nSjppvwm rat\r\nEgdmsv rat\r\nDank rat\r\nNquicjnw rat\r\nLh captain\r\nTdyaqaqln rat\r\nQtj rat\r\nTfgwijvq rat\r\nNbiso child\r\nNqthvbf woman\r\n'], 'output': ['Btmfats\r\nI\r\nUrcqv\r\nUjfrelpu\r\nSjppvwm\r\nEgdmsv\r\nDank\r\nNquicjnw\r\nTdyaqaqln\r\nQtj\r\nTfgwijvq\r\nWswwcvvm\r\nYghnogt\r\nWqle\r\nAhksnio\r\nKhkvaap\r\nNbiso\r\nNqthvbf\r\nOcmtsnwx\r\nWtyfc\r\nDstixj\r\nLh\r\n']}, {'input': ['36\r\nKqxmtwmsf child\r\nIze woman\r\nDlpr child\r\nK woman\r\nF captain\r\nRjwfeuhba rat\r\nBbv rat\r\nS rat\r\nMnmg woman\r\nSmzyx woman\r\nSr man\r\nQmhroracn rat\r\nSoqpuqock rat\r\nPibdq man\r\nIlrkrptx rat\r\nZaecfyqka man\r\nMmersfs child\r\nVvvocqi man\r\nHjeqxvq rat\r\nMpmb woman\r\nWmgu woman\r\nCerelmhoxi child\r\nA man\r\nDylv man\r\nXrdgmmtcpq woman\r\nXj woman\r\nCeh child\r\nOfccguo man\r\nNevr man\r\nAknkwdkq child\r\nBmo man\r\nLqo woman\r\nVej child\r\nT child\r\nRlijc man\r\nNsdtpdg woman\r\n'], 'output': ['Rjwfeuhba\r\nBbv\r\nS\r\nQmhroracn\r\nSoqpuqock\r\nIlrkrptx\r\nHjeqxvq\r\nKqxmtwmsf\r\nIze\r\nDlpr\r\nK\r\nMnmg\r\nSmzyx\r\nMmersfs\r\nMpmb\r\nWmgu\r\nCerelmhoxi\r\nXrdgmmtcpq\r\nXj\r\nCeh\r\nAknkwdkq\r\nLqo\r\nVej\r\nT\r\nNsdtpdg\r\nSr\r\nPibdq\r\nZaecfyqka\r\nVvvocqi\r\nA\r\nDylv\r\nOfccguo\r\nNevr\r\nBmo\r\nRlijc\r\nF\r\n']}, {'input': ['2\r\nA captain\r\nB man\r\n'], 'output': ['B\r\nA\r\n']}, {'input': ['2\r\nB woman\r\nA captain\r\n'], 'output': ['B\r\nA\r\n']}, {'input': ['2\r\nX child\r\nY captain\r\n'], 'output': ['X\r\nY\r\n']}, {'input': ['2\r\nX captain\r\nY rat\r\n'], 'output': ['Y\r\nX\r\n']}, {'input': ['6\r\nAbdelrhman captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n'], 'output': ['Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nAbdelrhman\r\n']}, {'input': ['4\r\nAratos captain\r\nMind child\r\nAman woman\r\nCarrot man\r\n'], 'output': ['Mind\r\nAman\r\nCarrot\r\nAratos\r\n']}]