function arrInt(arr) { return arr.map(str => parseInt(str, 10)) .sort((a, b) => a - b); } function Main(input) { const src = input.split("\n"); const n = parseInt(src[0]); const a = arrInt(src[1].split(" ")); let ans = a[0]; for (let i = 1; i < n; i++) { if (a[i - 1] != (a[i] - 1)) ans += a[i]; } console.log(ans); } Main(require("fs").readFileSync("/dev/stdin", "utf8"));