/*
Consigna:
1- Bajar node.js
2- Tomar dos standart input de un archivo txt, sumarlos y mostrarlos dentro de otro txt
3- Ambos argumentos deben estar validados

Uso:
$ node main.js <in.txt >>out.txt
*/

process.stdin.setEncoding('utf8');
if (process.stdin.isTTY) {
  process.stdout.write("Missing stdin redirection");
  process.exit(1);
}

let chunks = "";

process.stdin.on('data', (chunk) => {
  chunks+= chunk;
});

process.stdin.on('end', () => {
  const lines = chunks.trim().split(/\s+/);

  const numbers = lines.map(line => Number(line.trim()));

  numbers.forEach((x)=>{
    if (isNaN(x)){
      process.stdout.write("Invalid Input");
      process.exit(1);
    }
  });

  const sum = numbers.reduce((acc, curr) => acc + curr, 0);

  process.stdout.write(`${sum}\n`);
});
