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 Ruby (2.3.3) (judge verdict: Wrong Answer)

require 'prime'
pr = []
Prime.each(10**6) do |i|
  pr.push(i)
end
pr_ch = Array.new(pr.length, 0)
n = gets.to_i
for i in 0..pr.length-1
  if n % pr[i] == 0
    while n % pr[i] == 0
      pr_ch[i] += 1
      n /= pr[i]
    end
  end
  if n == 1
    break
  end
end
ans = 1
count = 1
for i in 0..pr.length-1
  inst = 1
  if pr_ch[i] > 0
    for j in 1..pr_ch[i]
      inst += pr[i]**j
    end
    count *= pr_ch[i]+1
    ans *= inst
  end
end
ans -= count - 1
if pr_ch[0] > 0
  ans -= 2
end
puts ans