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 Rust (1.42.0) (judge verdict: Accepted)

#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: i64,
    }

    // N / m = N % m = r と置いた時に、
    // N = r * m + r (ただし、 r < m)
    // N = r (m + 1)

    // N = 8のとき
    // (1, 8) (2, 4) [(4, 2) (8, 1) これらはr < m を満たさないのでNG]
    // 7, 3

    // O(sqrt(N)) で全探索いくかー!

    let mut ans: i64 = 0;
    let mut r = 1i64;
    while r * r <= N {
        if N % r != 0 {
            r += 1;
            continue;
        }

        let m = N / r - 1;
        if m == 0 {
            r += 1;
            continue;
        }

        if N / m == N % m {
            ans += m;
        }

        r += 1;
    }

    println!("{}", ans);
}