const reader = require("readline").createInterface({ input: process.stdin, output: process.stdout }); let lines = []; reader.on("line", line => { lines.push(line); }); reader.on("close", () => { const newArr = lines[0].split(' ').map(str => parseInt(str, 10)) const difference1 = newArr[2] - newArr[0] const difference2 = newArr[2] - newArr[1] function compare(n) { return (n >= 0) ? true : false; } const compareResult1 = compare(difference1) const compareResult2 = compare(difference2) const answer1 = newArr[2] const answer2 = newArr[2] - 1 const answer3 = newArr[2] - 2 switch (compareResult1) { case true: if (compareResult2) { console.log(answer3) } else { console.log(answer2) } break; default: if (compareResult2) { console.log(answer2) } else { console.log(answer1) } break; } });