process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function main() { var n = parseInt(readLine()); a = readLine().split(' '); a = a.map(Number); // your code goes here //first find the distance from 0 for all. var firstMin; var secondMin; var zeroDistance = []; if(a[0] > -1) { firstMin = { value: a[0], position: 0 }; secondMin = { value: a[0], position: 0 }; } else { firstMin = { value: (a[0] * -1), position: 0 }; secondMin = { value: (a[0] * -1), position: 0 }; } a.forEach(function(number, index) { if(number < 0) { var n = (number*(-1)); zeroDistance.push(n); } else { zeroDistance.push(number); } if(zeroDistance[index] < firstMin.value) { firstMin.value = zeroDistance[index]; firstMin.position = index; } }); zeroDistance.forEach(function(number, index) { if(number < secondMin.value && index !== firstMin.position) { secondMin.value = number; secondMin.position = index; } }); console.log(firstMin.value + secondMin.value); }