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.



Sample input:
8


Sample output:
10

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)

def divisions_(n):
    sq = int(math.sqrt(n)+1)
    ss = 30030
    a = [None] * (ss)
    a[0] = 1
    t = 1
    for i in range(2,ss):
        if not a[i] is None:
            continue
        if t * i > ss:
            break
        t *= i
        for j in range(i*2,ss,i):
            a[j] = 1
    a = [i for i in range(t) if a[i] is None]
    d = collections.defaultdict(int)
    for i in a[1:]:
        while n % i == 0:
            n //= i
            d[i] += 1

    for j in range(1,sq//t+2):
        if j > n:
            break
        for ii in a:
            i = t*j+ii
            while n % i == 0:
                n //= i
                d[i] += 1
    r = [1]
    for k, v in d.items():
        for c in r[:]:
            for i in range(1,v+1):
                r.append(c*(k**i))

    return sorted(r)
def divisions(n):
    sq = int(math.sqrt(n)+1)
    d = collections.defaultdict(int)
    while n % 2 == 0:
        n //= 2
        d[2] += 1
    i = 3
    while n > 1 and sq >= i:
        if n % i == 0:
            n //= i
            d[i] += 1
        else:
            i += 2

    if n > 1:
        d[n] += 1

    r = [1]
    for k, v in d.items():
        for c in r[:]:
            for i in range(1,v+1):
                r.append(c*(k**i))

    return sorted(r)

def main():
    n = I()
    ds = divisions(n)
    # print(ds)
    r = 0
    u = set([0])
    mk = ds[0]
    if len(ds) > 1:
        mk = ds[1]
    for k in ds:
        if k < 2:
            continue
        for a in range(1,mk):
            t = k - a
            if t in u:
                continue
            u.add(t)
            if n // t == n % t:
                r += t

    return r


print(main())

Submission status: Accepted

Solution code:
n=int(input())
res=0
if int(n**0.5)**2==n:
    ran=int(n**0.5)
else:
    ran=int(n**0.5)+1
for i in range(1,ran):
    if n%i==0:
        x=i
        m=n//i-1
        if x==m:
            break
        if x*(m+1)==n:
            res+=m
print(res)

Submission status: Accepted

Solution code:
n = int(input())
r = 0
for i in range(1, 10**6):
    if i*(i+1) >= n:
        break
    r = i
ans = 0
for i in range(1, r+1):
    if n % i == 0:
        ans += n//i - 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
i=1
D=[]
while i*i<=N:
  if N%i==0:
    D.append(i)
    D.append(N//i)
  i+=1
ans=0
for r in D:
  m=N//r-1
  if r<m:
    ans+=m
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=int(n**.5+1)
ans=0
for i in range(1,a+1):
  if n%i>0:
    continue
  if n//i>=i+2:
    ans+=n//i-1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for i in range(1, N):
    if (N - i) // i + 1 <= i:
        break
    if (N - i) % i == 0:
        if (N - i) // i <= i:
            break
        ans += ((N - i) // i)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

# n / y = a ... a
a = 1
ans = 0
while (a*a <= n):
	y = (n//a)-1
	if (n//a)*a == n and y>a:
		ans += y
	a+= 1

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    ans = 0
    for x in range(1, N + 1):
        m = N // x - 1
        if m <= x:
            break
        if N % x == 0:
            ans += m
    return ans

print(main())

Submission status: Accepted

Solution code:
N = int(input())

div = []
i = 1
while i * i <= N:
    if N % i == 0:
        div.append(i)
    if N // i != i:
        div.append(N // i)
    i += 1
div.sort()
prev = 0
ans = 0
for d in div:
    m = N // d - 1
    if m > 0 and N // m == N % m:
        ans += m

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3

import math


def solve(n):
    res = 0
    for q in range(1, math.floor(math.sqrt(n)) + 1):
        m1, mo = divmod(n, q)
        if mo != 0 or m1 - q < 2:
            continue
        res += m1 - 1
    return res


def main():
    n = int(input())
    res = solve(n)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

# N = mx + x and x < m

ans = 0
for x in range(1,N+1):
  if x*(x+2) > N:
    break
  m,r = divmod(N,x)
  if r != 0:
    continue
  ans += m - 1

print(ans)

Submission status: Accepted

Solution code:
import sys
range = xrange
input = raw_input

N = int(input())

div = 0
i = 1
while i*i<N:
    if N%i==0:
        m = i-1 
        if m and (m+1)*(N//m) == N: 
            div += m

        m = (N//i)-1 
        if m and (m+1)*(N//m) == N: 
            div += m
    i += 1

if i*i==N:
    m = i-1 
    if m and (m+1)*(N//m) == N: 
        div += m

print div

Submission status: Accepted

Solution code:
def make_divisors(n):
    res = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.add(i)
            res.add(n // i)
    return res


N = int(input())
s = make_divisors(N)
# print(s)
ans = 0
for ss in s:
    ss -= 1
    if ss <= 1: continue
    k, r = divmod(N, ss)
    if r == 0: continue
    if k >= ss: continue
    ans += ss
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        # nを合う数字で割り切れたら、その割った数と商をリストに追加する。
        # nが平方数のとき、同じ数字が2回追加されてしまうので3行したのif文がある
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

yakusuu_list = make_divisors(N)

cnt = 0
for yaku in yakusuu_list[::-1]:
    m = yaku-1
    a = N / yaku
    if a >= m:
        break
    else:
        cnt += m

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
def divisor_all(n): # 約数全列挙
    import math as ma
    l = [1,n]
    for i in range(2,int(ma.sqrt(n))+1):
        if n % i == 0:
            l.append(i)
            l.append(n//i)
    l.sort()
    return l # list
ll = divisor_all(N)
ans = 0
for i in range(len(ll)):
    r = ll[i]
    m = N//r-1
    if r<m:
        ans += m

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int):
    res = 0
    x = 1
    while x * x <= N:
        mp1, r = divmod(N, x)
        m = mp1 - 1
        if x >= m:
            break
        x += 1
        if r > 0:
            continue
        res += m
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for i in range(1, N + 1):
    if i * i > N:
        break
    if N % i > 0:
        continue
    if i < N // i - 1:
        ans += N // i - 1
    if N // i < i - 1:
        ans += i - 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
i = 1
ans = 0
while True:
    d, m = divmod(n, i)
    d -= 1
    if i >= d:
        break
    if m != 0:
        i += 1
        continue
    ans += d
    i += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

root_n = int(n ** 0.5)

ans = 0

for i in range(1, root_n + 1):
    if n % i == 0 and i < n // i - 1:
        ans += n // i - 1

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n = get_int()
    divs = filter(lambda x: n // x < x - 1, make_divisors(n))
    ans = sum(x - 1 for x in divs)
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import random
import itertools
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n = int(input())

import math
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n //= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
#a = factorization(n)
#b = []
#for i,j in a:
#  b.append(i)
def divisor_sub(p, q):
    a = []
    for i in range(0, q + 1):
        a.append(p ** i)
    return a

def divisor(n):
    if n == 1:
      return([1])
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)
#素因数列挙
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  table = set(table)
  table = list(table)
  return table

a = divisor(n)
ans = []
a.remove(n)
for i in a:
    b = (n-i)//i
    if n//b == n %b:
        ans.append(b)
print(sum(ans))

Submission status: Accepted

Solution code:
N = int(input())

res = 0


for p in range(1, 10**6+2):
    if N % p == 0:
        q = N // p - 1
        if q > p:
            res += q
        else:
            break

print(res)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
yaku = set()
for x in range(1,int(math.sqrt(N))+1):
    if N % x == 0:
        yaku.add(x)
        yaku.add(N//x)

yaku = sorted(list(yaku))
L = len(yaku)
ans = 0
for i in range(1,L):
    if yaku[i] - yaku[i-1] !=1:
        tmp = yaku[i]-1
        if N//tmp == N%tmp:
            ans += tmp

print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())

divisors = []
for i in range(1, int(math.sqrt(N))+2):
    if N%i == 0:
        if i < N//i:
            divisors.append(i)
            divisors.append(N//i)
        elif i == N//i:
            divisors.append(i)
ans = 0
for elem in divisors:
    m = elem-1
    p = N//(m+1)
    if 0 <= p and p < m:
        ans += m
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=set()
ans=0
index=1
while(index*index<=N):
    if N%index==0:
        S.add(index)
        S.add(N//index)
    index+=1
for k in S:
    if k==1:
        continue
    m=k-1
    if (N//m)==(N%m):
        ans+=m
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for r in range(1,N+1):
    if r*(r+1)>=N:
        break
    if N%r == 0:
        ans += N//r-1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

t1=2
comb=set()
while t1*t1<=n:
    if n%t1==0:
        t2=n//t1

        m=t1-1
        if t2==n%m:
            comb.add(m)
        m=t2-1
        if t1==n%m:
            comb.add(m)
    t1+=1

m=n-1
print(sum(comb)+n-1 if n==(m+1)*(n%m) else sum(comb))

Submission status: Runtime Error

Solution code:
import math

N = int(input())
ans = 0
for i in range(1, int(math.sqrt(N)) + 2):
    if N % i:
        continue
    m = N // i - 1
    if N // m == N % m:
        ans += m
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

class factorials:
    '''
    args:
      n : max val when exploring factorials
    '''
    def __init__(self, n):
        self.n = 1# factorials to be searched
        self.factorials = []
        self.update_factorials(n)

    def update_factorials(self, n):
        if self.n >= n:
            return None
        for i in range(self.n+1, n+1):
            done = False
            limit = int(i ** 0.5)
            for j in self.factorials:
                if j > limit: break
                if not i % j:
                    done = True
                    break
            if not done:
                self.factorials.append(i)
        self.n = n
        return None

    def factorials_list(self):
        return self.factorials

    def check_fact(self, x):
        if x > self.n**2:
            self.update_factorials(int(x ** 0.5)+1)
        MAX = int(math.sqrt(x))
        for f in self.factorials:
            if f > MAX:break
            if not x % f:
                return False
        return True

    def prime_factorization(self, val, divisors=None):
        # divisors : default-dict of divisors. Should be specified only if appended vals are required
        max_n = int(math.sqrt(val))
        if self.n < max_n:
            self.update_factorials(max_n)
        if divisors == None:
            divisors = defaultdict(lambda: 0)
        for f in self.factorials:
            if f > val: break
            while True:
                if not val % f:
                    divisors[f] += 1
                    val //= f
                else:
                    break
        if val > 1:
            divisors[val] += 1
        return divisors



def run():
    N = int(input())
    facts = factorials(int(N ** 0.5))
    dic = facts.prime_factorization(N)
    #print(dic)
    ret = 0

    def dfs(x, l, v):
        nonlocal ret
        #print(x,l,v)
        xx, ll = x[0], l[0]
        if len(x) == 1:
            for i in range(ll+1):
                tmp = v * (xx ** i)
                #print(tmp)
                if tmp == 1:continue
                if N % (tmp-1) == N // (tmp-1):
                    #print(tmp)
                    ret += tmp-1

        else:
            for i in range(ll + 1):
                tmp = v * xx ** i
                dfs(x[1:], l[1:], tmp)

    dfs(list(dic.keys()), list(dic.values()), 1)

    print(ret)

if __name__ == "__main__":
    run()

Submission status: Runtime Error

Solution code:
N=int(input())

if N == 0:
  print(0)
  exit()

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)

Submission status: Runtime Error

Solution code:
import sympy
N=int(input())
S=sympy.divisors(N)
ans=0
S=S[1:]
for i in S:
   if i==0:
      continue
   if N%(i-1)==N//(i-1):
      ans+=i-1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 0
for i in range(1,1250000):
    if(((N-i)/i).is_integer() and N//((N-i)/i) == N%((N-i)/i)):
        # print((N-i)//i,i)
        ans += ((N-i)//i)
        # if(i == 800000):
        #     print(ans)
    # print(i)
print(ans)

Submission status: Runtime Error

Solution code:
import math
def prime_divisor(n):
    ls = []
    i = 2
    while i <= math.floor(n**0.5):
        if n%i == 0:
            ls.append(i)
            ls.append(n//i)
            i += 1
        else:
            i += 1
    if n > 1:
        ls.append(n)
    return ls
N = int(input())
ls1 = prime_divisor(N)
ls2 = [x-1 for x in list(set(ls1)) if x >= 2]
ls2.sort()
ls2.reverse()
ans = 0
for i in range(len(ls1)):
    if N // ls2[i] == N % ls2[i]:
        ans += ls2[i]
print(ans)

Submission status: Runtime Error

Solution code:
import math
def prime_divisor(n):
    ls = []
    i = 2
    while i <= math.floor(n**0.5):
        if n%i == 0:
            ls.append(i)
            ls.append(n//i)
            i += 1
        else:
            i += 1
    if n > 1:
        ls.append(n)
    return ls
N = int(input())
ls1 = prime_divisor(N)
ls2 = [x-1 for x in list(set(ls1)) if x >= 2]
ls2.sort()
ls2.reverse()
print(ls2)
ans = 0
for i in range(len(ls1)):
    if N // ls2[i] == N % ls2[i]:
        ans += ls2[i]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


# 約数から1引いたものが候補
arr = make_divisors(n)
arr = [x - 1 for x in arr]

#　商と剰余が不一致ならbreakできる
ans = 0
for x in arr[::-1]:
    if n // x != n % x:
        break
    ans += x

print(ans)

Submission status: Runtime Error

Solution code:
import math


def main():
    n = int(input())
    a = []
    for i in range(1, (int)(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                a.append(i - 1)
            a.append((n // i) - 1)
    a.sort()
    ans = 0
    if len(a) == 0:
        ans = 0
    else:
        for i in a:
            if i != 1 and (n // i == n % i):
                ans += i
    print(ans)


main()

Submission status: Runtime Error

Solution code:
import math
def main():
    n = int(input())
    a = []
    for i in range(1,(int)(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                a.append(i - 1)
            a.append((n // i) - 1)
    a.sort()
    ans = 0
    for i in a:
        if i != 1 and (n // i == n % i):
            ans += i
    print(ans)
main()

Submission status: Runtime Error

Solution code:
import math
def main():
    n = int(input())
    a = []
    for i in range(1,(int)(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                a.append(i - 1)
            a.append(n // i - 1)
    a.sort()
    print(a)
    ans = 0
    for i in a:
        if i != 1 and n // i == n % i:
            ans += i
    print(ans)
main()

Submission status: Runtime Error

Solution code:
def prime(p):
    memo = [p]
    for i in range(2,(int(p**0.5)+1)):
        if p%i == 0:
            memo.append(i)
            memo.append(p//i)
    return memo

x = int(input())

memo = prime(x)

ans = 0

for i in memo:
    if x%(i-1)==x//(i-1):
        ans += i-1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
i = 1
divs = []
while i ** 2 <= N:
    if N % i == 0:
        divs.append((i, N // i))
    i += 1

ans = 0
for p in divs:
    r = p[0]
    m = p[1] - 1
    if N % m == r:
        ans += m
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
i = 1

def calc(x):
    x -= 1
    if n // x == n % x:
        return x
    return 0

for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        if i != 1:
            ans += calc(i)
        ans += calc(n // i)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab = list(map(lambda x: [x[0], x[1], x[0]+x[1]], ab))
ab.sort(key=lambda x:x[2], reverse=True)
ab=deque(ab)
count = 0
ans=0
while len(ab)>0:
  a, b, dif = ab.popleft()
  if count%2==0:
    ans+=a
  else:
    ans-=b
  count+=1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab = list(map(lambda x: [x[0], x[1], x[0]+x[1]], ab))
ab.sort(key=lambda x:x[2], reverse=True)
ab=deque(ab)
count = 0
ans=0
while len(ab)>0:
  a, b, dif = ab.popleft()
  if count%2==0:
    ans+=a
  else:
    ans-=b
  count+=1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
x,r = 1,0

while x*x <= N:
	if N%x==0:
		if x>1 and N//(x-1)==N%(x-1):
			r += x-1
		t = N//x-1
		if N//t==N%t:
			r += t
	x += 1

print(r)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 0
for i in range(1,N+1):
    if N % i == 0:
        temp = N // i - 1
        d,m = divmod(N,temp)
        if d != m:
            break
        else:
            ans += temp
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

ans = 0
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0 and n // (i - 1) == n % (i - 1):
        ans += i - 1
    m = n // i - 1
    if m > 0 and n % i == 0 and n // m == n % m:
        ans += m
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

ans = 0
for i in range(1, int(n ** 0.5) + 1):
    m = n // i - 1
    if n % i == 0 and n // m == n % m:
        ans += m
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
from math import gcd
cou = 0
for i in range(1,int(n**0.5)+1):
  if n%i==0:
    b = n//i-1
    if n//b==n%b:
      cou += b
    
    if i>2:
      c = i-1
      if n//c==n%c:
        cou += c
print(cou)

Submission status: Runtime Error

Solution code:
N = int(input())
lim = int(N ** 0.5) + 1
ans = 0
for i in range(1, lim + 1):
    m = N // i
    quotient = N // m
    while m != 0:
        remainder = N % m
        if N // m != quotient or remainder > i:
            break
        if quotient == remainder:
            ans += m
            break
        m -= 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = set()

for i in range(1,int(n**0.5)+2):
    if n//i == n%i:
        s.add(i)
    x = (n-i)//i
    if n//x== n%x:
        s.add(x)
print(sum(list(s)))

Submission status: Runtime Error

Solution code:
#素因数分解
def Prime_Factorization(n):
    R=[]
    N=n

    for k in range(2,int(-(-n**0.5//1))+1):
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])

    if N!=1:
        R.append([N,1])
        
    if not R:
        R.append([N,1])

    return R

#約数全部
from copy import copy
def Divisors(n):
    L=Prime_Factorization(n)
    U=[1]

    for (p,k) in L:
        T=copy(U)
        for t in T:
            r=t
            for _ in range(1,k+1):
                r*=p
                U.append(r)
    U.sort()
    return U

N=int(input())
L=Divisors(N)
L.remove(1)

K=0
for a in L:
    b=a-1
    if N//b==N%b:
        K+=b
print(K)

Submission status: Runtime Error

Solution code:
import unittest


def solve_small(n):
    total = 0
    for m in range(1, n):
        if n // m == n % m:
            total += m
    return total


def solve(n):
    conds = set()
    conds.add(n-1)
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            conds.add(i-1)
            conds.add(n // i - 1)
    total = 0
    for m in list(conds):
        if n // m == n % m:
            total += m
    return total


def main():
    n = int(input())
    result = solve(n)
    print(result)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 8
        actual = solve(n)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 1000000000000
        actual = solve(n)
        expected = 2499686339916
        self.assertEqual(actual, expected)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  divisors.sort()
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
D = make_divisors(n)
ans = 0
for k in D:
  m =  N//k-1
  if m>k:
    ans += m
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
if n==1:
    print(0)
pf={}
m=n
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
ans=[]
m=0
for i in range(1, int(n**0.5)+1):
    if n%i==0:
        m=n//i-1
        if n%m==i and n//m==i:
            ans.append(m)

#print(int(n**0.5))
print(sum(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
pf={}
m=n
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
ans=[]
m=0
for i in range(1, int(n**0.5)+1):
    if n%i==0:
        m=n//i-1
        if n%m==i and n//m==i:
            ans.append(m)

#print(int(n**0.5))
print(sum(ans))

Submission status: Runtime Error

Solution code:
N=int(input())
ans=0
for i in range(1,int(N**0.5)+1):
    if (N-i)%i==0:
        q=(N-i)//i
        if N%q==i:
            ans+=(N-i)//i
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

#n=m*a+a
#n=(m+1)*a
#m>a

cnt=0
for i in range(1,int(n**(0.5))+1):
    if n%i==0:
        m=n//i-1
        if n%m==n//m:
            cnt+=m
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())

ans = 0
for k in range(1, int(n**(1/2))+1):
    m = (n - k) // k
    if n // m == n % m:
        ans += m

print(ans)