Problem:
Score : 500 points

Problem Statement

Snuke received a positive integer N from Takahashi.
A positive integer m is called a favorite number when the following condition is satisfied:

The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.

Find all favorite numbers and print the sum of those.

Constraints

All values in input are integers.

1 \leq N \leq 10^{12}

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

8

Sample Output 1

10

There are two favorite numbers: 3 and 7. Print the sum of these, 10.

Sample Input 2

1000000000000

Sample Output 2

2499686339916

Watch out for overflow.

Solution in JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

!function(n){var t={};function e(r){if(t[r])return t[r].exports;var u=t[r]={i:r,l:!1,exports:{}};return n[r].call(u.exports,u,u.exports,e),u.l=!0,u.exports}e.m=n,e.c=t,e.d=function(n,t,r){e.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:r})},e.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},e.t=function(n,t){if(1&t&&(n=e(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var u in n)e.d(r,u,function(t){return n[t]}.bind(null,u));return r},e.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(t,"a",t),t},e.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},e.p="",e(e.s=2)}([function(n,t){n.exports=require("fs")},function(n,t){n.exports=require("readline")},function(n,t,e){"use strict";e.r(t);var r={A_DoubleHelix:function(n){switch(n[0]){case"A":return["T"];case"T":return["A"];case"C":return["G"];case"G":return["C"];default:throw new Error("invalid string")}},B_ATCoder:function(n){for(var t=n[0],e=0,r=0,u=0;r<t.length;r+=1)o=t[r],"A"===o||"T"===o||"C"===o||"G"===o?u+=1:u>e&&(e=u,u=0);var o;return u>e&&(e=u),[String(e)]},C_GeT_AC:function(n){var t=n[0].split(" ").map(function(n){return Number(n)}),e=(t[0],t[1],n[1]),r=n.slice(2).map(function(n){return n.split(" ").map(function(n){return Number(n)})}),u=e.split("").map(function(n,t,e){return"A"===n&&e.length>t+1&&"C"===e[t+1]});return r.map(function(n){for(var t=n[0],e=n[1],r=0,o=t-1;o<e-1;o+=1)u[o]&&(r+=1);return String(r)})}},u={c:function(n){n[0].split(" ").map(function(n){return Number(n)})[0];var t=n.slice(1),e=0,r=0,u=0,o=0;return t.forEach(function(n,t){"B"===n[0]&&(u+=1),"A"===n[n.length-1]&&(r+=1),"B"===n[0]&&"A"===n[n.length-1]&&(o+=1),e+=(n.match(/AB/g)||[]).length}),r-o==0&&u-o==0?[String(e+o-1)]:[String(r<u?r+e:u+e)]},d:function(n){for(var t=n[0].split(" ").map(function(n){return Number(n)})[0],e=0,r=Math.sqrt(t),u=1;u<r;u+=1){var o=(t-u)/u;Number.isInteger(o)&&(e+=o)}return[String(e)]}},o=!0,i=!1;function c(n){var t=function(n){for(var t=[],e=0;e<n.length-1;e+=1)n[e]===o&&n[e+1]===i&&t.push(e);return t}(n);return 0===t.length?0:1+Math.max.apply(Math,t.map(function(t){return c(function(n,t){var e=n.concat();return e[t]=!e[t],e[t+1]=!e[t+1],e}(n,t))}))}function a(n){return n.length<2?0:Math.max.apply(Math,n.map(function(t,e){var r=n.filter(function(n,t){return t!==e});return Math.max.apply(Math,r.map(function(n,e){return function(n,t){var e=n+t;return 0==(e&e-1)}(t,n)?a(r.filter(function(n,t){return t!==e}))+1:0}))}))}var l={AIrreversibleOperation:function(n){return[c(n[0].split("").map(function(n){return"B"===n}))]},BPowerOfTwo:function(n){Number(n[0]);var t=function(n){var t=n.filter(function(n){return n%2==1}),e=n.filter(function(n){return n%2==0});return{odds:t,evens:e}}(n[1].split(" ").map(function(n){return Number(n)})),e=t.odds,r=t.evens;return[a(e)+a(r)]}},f=e(0),s=e.n(f),p=e(1);function h(){process.stdin.resume(),process.stdin.setEncoding("utf8");var n=[],t=p.createInterface({input:process.stdin,output:process.stdout});return t.on("line",function(t){n.push(t)}),new Promise(function(e){t.on("close",function(){e(n)})})}var v=function(n,t,e,r){return new(e||(e=Promise))(function(u,o){function i(n){try{a(r.next(n))}catch(n){o(n)}}function c(n){try{a(r.throw(n))}catch(n){o(n)}}function a(n){n.done?u(n.value):new e(function(t){t(n.value)}).then(i,c)}a((r=r.apply(n,t||[])).next())})},d=function(n,t){var e,r,u,o,i={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;i;)try{if(e=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(u=(u=i.trys).length>0&&u[u.length-1])&&(6===o[0]||2===o[0])){i=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){i.label=o[1];break}if(6===o[0]&&i.label<u[1]){i.label=u[1],u=o;break}if(u&&i.label<u[2]){i.label=u[2],i.ops.push(o);break}u[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(n,i)}catch(n){o=[6,n],r=0}finally{e=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}};function b(n){return v(this,void 0,void 0,function(){var t,e,r,u,o,i;return d(this,function(c){switch(c.label){case 0:return 1===n.length?[2,n]:(t=n.slice(0,Math.ceil(n.length/2)),e=n.slice(Math.ceil(n.length/2)),[4,b(t)]);case 1:return r=c.sent(),[4,b(e)];case 2:u=c.sent(),o=[],c.label=3;case 3:return r.length>0&&u.length>0?[4,m(r[0],u[0])]:[3,5];case 4:return(i=c.sent()?r.shift():u.shift())&&o.push(i),[3,3];case 5:return o.push.apply(o,r.concat(u)),[2,o]}})})}function m(n,t){return v(this,void 0,void 0,function(){return d(this,function(e){switch(e.label){case 0:return console.log("? "+n+" "+t),[4,s.a.readFileSync("/dev/stdin","utf8")];case 1:return[2,"<"===e.sent()]}})})}var y={beginner_contest_122:r,Diverta2019ProgrammingContest:u,GrandContest029:l,interactiveSorting:function(n){return v(this,void 0,void 0,function(){var t,e,r;return d(this,function(u){switch(u.label){case 0:return t=n[0].split(" ").map(function(n){return Number(n)}),e=t[0],t[1],r="A".charCodeAt(0),[4,b(Array.apply(null,new Array(e)).map(function(n,t){return String.fromCharCode(r+t)}))];case 1:return[2,["! "+u.sent().join("")]]}})})},welcomeToAtCoder:function(n){var t=Number(n[0]),e=n[1].split(" ").map(function(n){return Number(n)});return[t+e[0]+e[1]+" "+n[2]]}},g=function(n,t,e,r){return new(e||(e=Promise))(function(u,o){function i(n){try{a(r.next(n))}catch(n){o(n)}}function c(n){try{a(r.throw(n))}catch(n){o(n)}}function a(n){n.done?u(n.value):new e(function(t){t(n.value)}).then(i,c)}a((r=r.apply(n,t||[])).next())})},w=function(n,t){var e,r,u,o,i={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;i;)try{if(e=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(u=(u=i.trys).length>0&&u[u.length-1])&&(6===o[0]||2===o[0])){i=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){i.label=o[1];break}if(6===o[0]&&i.label<u[1]){i.label=u[1],u=o;break}if(u&&i.label<u[2]){i.label=u[2],i.ops.push(o);break}u[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(n,i)}catch(n){o=[6,n],r=0}finally{e=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}};!function(){g(this,void 0,void 0,function(){var n;return w(this,function(t){switch(t.label){case 0:return[4,h()];case 1:return n=t.sent(),y.Diverta2019ProgrammingContest.d(n).forEach(function(n){return console.log(n)}),[2]}})})}()}]);
//# sourceMappingURL=main.js.map