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: Runtime Error

Solution code:
import math
N = int(input())
n = int(math.sqrt(N))
ans = 0
for x in range(1, n+1):
    m = N // x - 1
    if N % x == 0 and x == N % m:
        ans += m
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

Submission status: Runtime Error

Solution code:
N=int(input())
s=list(input() for _ in range(N))
ans=0
count=0
a_count=0
b_count=0
ab_count=0
for i in s:
    ans+=i.count('AB')
    if i[0]=='B'and i[-1]=='A':
        ab_count+=1
    elif i[0]=='B':
        b_count+=1
    elif i[-1]=='A':
        a_count+=1
print(ans+min(a_count,b_count)+ab_count if a_count+b_count!=0 else ans+max(ab_count-1,0))

Submission status: Runtime Error

Solution code:
N = int(input())

kmax = math.floor((-1+math.sqrt(1+4*N))/2)
acc = 0
for k in range(1, kmax+1):
    if((N-k)%k==0):
        acc+=(N-k)/k
print(int(acc))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

m = math.floor(n/2)
if n>2:
    q = int( n / m )
    lm= m
    s = n - 1
else:
    s = 0

while( m>1 ):
    m = math.floor(n/(q+1))
    r0 = n % ( m + 1 )
    if r0>=q:
        d= r0  - q
        if d%q==0:
            s+= ( m+1+int(d/q) )
    #
    # for next
    q = int( n/m )
    lm= m
#
print( s )

Submission status: Runtime Error

Solution code:
n = int(input())
m = 1
ans = 0
"""
for m in range(1, int(n**0.5)+1):
    if n%m == 0 and m < n//m:
        ans += n//m -1
"""
while m <= int(sqrt(n)):
    if n % m == 0 and m < n // m:
        ans += n // m - 1
    m += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
m = 1
ans = 0
while m <= int(sqrt(n)):
    if n % m == 0 and m < n // m:
        ans += n // i - 1
    m += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
m = 1
ans = 0
while m <= sqrt(n):
    if n % m == 0 and m < n // m:
        ans += n // i - 1
    m += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
limit = int(math.ceil(math.sqrt(n)))
ans =0
for i in range(1,limit):
    a = n // i - 1
    if i * a + i == n:
        ans += a
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

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)
  return divisors

div = make_divisors(N)
ans = 0
for d in div:
  if N // (d - 1) == N % (d - 1):
    ans += d - 1

print(ans)

Submission status: Runtime Error

Solution code:

def get(N):#約数
	out=[]
	for i in range(1,N**0.5):
		if(N%i==0):
			out.append(i)
			out.append(N//i)
	if(out[-1]==out[-2]):
		out=out[:-1]
	return out



N=int(input())

L=range(N+1)
A=sorted(get(N))
s=0
for i in range(1,len(A)):

	Q=N//A[i]
	if(Q%(N%(A[i]-1))==0 and Q<(N%(A[i-1]+1))):
		s+=A[i]-Q//(N%(A[i]-1))			
print(s)

Submission status: Runtime Error

Solution code:
import numpy

N = int(input())
ans = 0
for m in range(numpy.sqrt(N)):
    if N // (m + 1) == N % (m + 1):
        ans += m + 1
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int):
    ret = 0

    for i in range(1, int(sqrt(N)) + 1):
        if N % i != 0:
            continue

        m = (N // i) - 1
        if (N // m) == (N % m):
            ret += m
    return ret


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
    result = solve(N)
    if isinstance(result, Iterable):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = input()

result = 0

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)
    return divisors

for i in make_divisors(n):
    x = n//c - 1
    if n%x == n//x:
        result+=x

print(result)

Submission status: Runtime Error

Solution code:
N = int(input())
c = 0
for m in range(1,N+1):
	if N//m == N%m:
    	c += m
print(c)

Submission status: Runtime Error

Solution code:
def hantei(p, q):
  ANS = divmod(p, q)
  if ANS[0] == ANS[1]:
    return q
  else 0
  
N = int(input())
ans = [hantei(N, r) for r in range(N) if hantei(N, r) != 0]
print(sum(ans))

Submission status: Runtime Error

Solution code:
import math

n= int(input())

m = math.floor(n/2)
q = int( n / m )
lm= m

s = n - 1
while( m!=1 ):
    m = math.floor(n/(q+1))
    r0 = n % ( m + 1 )
    if r0>=q:
        d= r0  - q
        if d%q==0:
            s+= ( m+1+int(d/q) )
    #
    # for next
    q = int( n/m )
    lm= m
#
print( s )

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
count = 0 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if i > 2 and (n/i-1 > i):
              divisors.append(i)
            if (n/i-1 > i) and (i != n // i ):
              divisors.append(n//i)
            #if i != n // i:
              #divisors.append(n//i)

    divisors.sort()
    if divisors[0] == 1:
      del divisors[0]
    if divisors[0] == 2:
      del divisors[0]
    return divisors
a = make_divisors(n)
print(sum(a)-len(a))

Submission status: Runtime Error

Solution code:


def get(N):#約数
	out=[]
	for i in range(1,N**0.5):
		if(N%i==0):
			out.append(i)
			out.append(N//i)
	if(out[-1]==out[-2]):
		out=out[:-1]
	return out



N=int(input())

L=range(N+1)
A=sorted(get(N))
s=0
for i in range(1,len(A)):

	Q=N//A[i]
	if(Q%(N%(A[i]-1))==0 and Q<(N%(A[i-1]+1))):
		s+=A[i]-Q//(N%(A[i]-1))			
print(s)

Submission status: Runtime Error

Solution code:
a = int(input())
def d(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
s = 0
t = d(a)
#print(t)
for i in range(len(t)):
    if t[i]>=math.sqrt(a):break
    #print(t[i])
    s+=(a-t[i])//(t[i])
print(s)

Submission status: Runtime Error

Solution code:
N=int(input())
a=0
B=0
A=0
count1=0
count2=0
for i in range(N):
    S=input()
    a+=S.count("AB")
    if S[0]=="B"and S[len(S)-1]=="A":
        a+=1
        count1+=1
    elif S[0]=="B":
        B+=1
        count2+=1
    elif S[0]=="A":
        A+=1
        count2+=1
if count1!=0:
    A+=1
    B+=1
if count2==0:
    a=a-1
C=min(A,B)
D=min(C,N-1)
print(a+D)

Submission status: Runtime Error

Solution code:

def get(N):#約数
	out=[]
	for i in range(1,N**0.5):
		if(N%i==0):
			out.append(i)
			out.append(N//i)
	if(out[-1]==out[-2]):
		out=out[:-1]
	return out



N=int(input())

L=range(N+1)
A=sorted(get(N))
s=0
for i in range(1,len(A)):

	Q=N//A[i]
	if(Q%(N%(A[i]-1))==0 and Q<(N%(A[i-1]+1))):
		s+=A[i]-Q//(N%(A[i]-1))			
print(s)

Submission status: Runtime Error

Solution code:
import sympy

a = int(input())

test_list = sympy.divisors(a)
test_list_modify = [i-1 for i in test_list if i > 2 and a//(i-1) == a%(i-1)]
print(sum(test_list_modify))

Submission status: Runtime Error

Solution code:
def get(N):#約数
	out=[]
	for i in range(1,N**0.5):
		if(N%i==0):
			out.append(i)
			out.append(N//i)
	if(out[-1]==out[-2]):
		out=out[:-1]
	return out



N=int(input())

L=range(N+1)
A=sorted(get(N))
s=0
for i in range(1,len(A)):

	Q=N//A[i]
	if(Q%(N%(A[i]-1))==0 and Q<(N%(A[i-1]+1))):
		s+=A[i]-Q//(N%(A[i]-1))			
print(s)

Submission status: Runtime Error

Solution code:
import numpy as np
def eratosthenes(n):
    is_prime = np.ones((n+1,), dtype=bool)
    is_prime[:2] = False
    for i in range(2,n+1):
        if is_prime[i]:
            is_prime[i*2::i]=False
    return np.arange(n+1)[is_prime]
Ps = eratosthenes(1000007)
def divisor(n):
    for p in Ps:
        if p*p>n:return -1
        if n%p==0:return p
def prime_division(n):
    d={}
    while n>1:
        p=divisor(n)
        if p==-1:d[n]=d.get(n,0)+1;break
        else:d[p]=d.get(p,0)+1;n//=p
    return d

def z(n,k,v):
    if len(k)==1:
        return [n*k[0]**i for i in range(v[0]+1)]
    else:
        r=[]
        for i in range(v[0]+1):
             r+=z(n*k[0]**i,k[1:],v[1:])
        return r
def y(n):
    pd=prime_division(n)
    KV=[[k,v] for k,v in pd.items()]
    K=[k for k,v in KV]; V=[v for k,v in KV]
    return z(1,K,V)

N=int(input())
r=0
#print(y(N))
for yk in y(N):
    if yk>1 and N//(yk-1) == N%(yk-1):
        r+=yk-1
print(r)

Submission status: Runtime Error

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


def solve(N: int, s: "List[str]"):
    count = 0
    for string in s:
        count += string.count('AB')

    count_A = 0
    count_B = 0
    count_both = 0
    
    for string in s:
        if string[-1] == 'A':
            count_A += 1
        if string[0] == 'B':
            count_B += 1
        if string[-1] == 'A' and string[0] == 'B':
            count_both += 1
    
    count += max(0, min(count_A - count_both, count_B - count_both))
    
    if abs(count_A - count_B) >= count_both:
        count += count_both
    else:
        count += abs(count_A - count_B) + int((count_both - abs(count_A - count_B)))
        if abs(count_A - count_B) == 0:
            count -= 1
    print(count)
    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
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
lst = range(2, n)

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

divisors.pop(0)
divisors.pop(1)
print(sum(divisors))

Submission status: Runtime Error

Solution code:
# N = mr + r
# N = m+1(r)
# N の倍数の
def factorize(n):
    val = n
    p = 2
   # factor=[0]*n
    res = []
    while p*p <= n:
        while val % p == 0:
            #factor[p]+=1
            res.append(p)
            val /= p
        p += 1
    if val > 1:
        res.append(int(val))
    return res


factor = 1
N = int(input())
A = factorize(N)
ary = [0]*A[len(A)-1]
for i in A:
    ary[i-1]+=1
if len(A) == 1:
    ans = 0
else:
    ans = 1
for j in range(len(ary)):
    tmp = 0

    if ary[j] != 0:
        factor *= ary[j] + 1
        for k in range(ary[j]+1):
            tmp += (j+1)**k
        ans *= tmp

print(ans - factor-1)

Submission status: Runtime Error

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


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


divisorsN = make_divisors(N)[:-1]
if N // divisorsN[-1] == 2:
    divisorsN = divisorsN[:-1]

ans = sum([N // divisor - 1 for divisor in divisorsN])

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
result = 0
for i in range(int(N/2)+1)
  if(i == 0)
    continue
  quo = N // i
  mod = N % i
  for j in range(quo)
    tmp = N - (quo - j)*i
    if(tmp == i):
      result += quo - j
    else if(tmp  < i):
      break
print(result)

Submission status: Runtime Error

Solution code:
n=input()
n+='L'
n=int(n)
def make_divisors(m):
  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)
  return divisors
y=make_divisors(n)
totl=0
for j in range(len(y)):
  if n==y[j]*((n//y[j])+1):
    totl+=n//y[j]
print(totl)

Submission status: Runtime Error

Solution code:
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

def calc(tp):
    ans = 1
    for a in tp:
        ans *= a
    return ans

soinsu = factorize(n)
yakusu = []
for i in range(len(soinsu)):
    yakusu += [a for a in itr.combinations(soinsu, i+1) ]

yakusu = set(yakusu)

ans = 0
for a in yakusu:
    c = calc(a)
    if c < math.sqrt(n):
        continue
    sho = n // (c-1)
    amari = n % (c-1)
    if sho == amari:
        ans += (c-1)

print(ans)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
import sympy

a = int(input())

test_list = sympy.divisors(a)
test_list_modify = [i-1 for i in test_list if i > 2]
print(test_list_modify)
print(sum(test_list_modify))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

n = int(input())
s = 0

for p in range(1, int(math.sqrt(n)) + 1):
  t = (n - p) / p
  if t.is_integer():
    if (n // int(t)) == (n % int(t)):
      s += int(t)

print(s)

Submission status: Runtime Error

Solution code:

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 bin_search(l):
    tmp=l[:]
    n=len(tmp)
    if n==1:
        if hoge//tmp[0]==hoge%tmp[0]:
            return tmp[0]
        else:
            return 0
    while n>0:
        if n%2==1:
            n+=1
        
        n=n//2
        #print("check")
        #print(tmp)
        #print(n)
        try:
            if hoge//tmp[n]==hoge%tmp[n]:
                return tmp[n]
            elif hoge//tmp[n]<hoge%tmp[n]:
                tmp=tmp[n:]
            elif hoge//tmp[n]>hoge%tmp[n]:
                tmp=tmp[:n]
        except:
            break
        
    return 0
        
hoge=int(input())
tmp=make_divisors(hoge)
tmp.sort()    
total=0
for i in range(len(tmp)-1):
    j=list(range(tmp[i]+1,tmp[i+1]))
    if len(j)>0:
        total+=bin_search(j)
        
print(total)

Submission status: Runtime Error

Solution code:
N = int(input())

sum = 0
for i in range (1,N+1):
    if N//i == N%i:
        sum += i
array.append(sum)
print(sum)

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[1]:

import sys
#input = sys.stdin.readline
N = int(input())


# In[3]:

import numpy as np


# In[9]:

a = np.arange(1, N//2)
nN = np.ones(N//2-1)*N
print(np.sum((nN/a-1)[(nN/a-1)%1==0]))


# In[ ]:

Submission status: Runtime Error

Solution code:
import sympy

a = int(input())

test_list = sympy.divisors(a)
test_list_modify = [i-1 for i in test_list if i > 2 or i!=8]
print(sum(test_list_modify))

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
for i in range(int(n/2)):
    if int(n/i) == n%i:
       ans+=i

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int):
    ret = 0

    for i in range(1, int(sqrt(N)) + 1):
        m = (N-1) // i
        if (N // m) == (N % m):
            ret += m
    return ret


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
    result = solve(N)
    if isinstance(result, Iterable):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
S = []

A = 0
B = 0
AB = 0

cnt = 0 

for _ in range(N):
    Si = input()
    cnt += Si.count('AB')
    if Si[0] == 'B' and Si[-1] == 'A':
        AB += 1
    elif Si[0] == 'B':
        B += 1
    elif Si[-1] == 'A':
        A += 1

if AB > 1:
    cnt += AB -2 
    if A > 0:
        cnt += 1
        A -= 1
    if B > 0:
        cnt += 1
        B -= 1
    if A > B :
        cnt += B
    else:
        cnt += A
else: 
    if A > B :
        cnt += B
    else:
        cnt += A
print(cnt)

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[1]:

import sys
input = sys.stdin.readline
N = int(input())


# In[2]:

import numpy as np


# In[9]:

#sum_ = 0
a = np.arange(1, N//2)
print(np.sum(N/a[(N/a-1)%1==0]-1))
#print(a)
#print(np.sum(a[N//a==N%a]))
#print(a)
#for m in range(1, (N-2)//2):
#    if (N-m)%m==0:
#        print(m)
#        sum_ += (N-m)/m
#print(sum_)


# In[ ]:

Submission status: Runtime Error

Solution code:
import sympy
import itertools

def calc_m(fs):
    ans = 1
    for i, k in enumerate(facts):
        ans *= k**(fs[i]+1)
    if(ans > 2):
        return ans - 1
    return 0

N = int(input())
facts = sympy.factorint(N)
roop = []
res = 0
for v in facts.values():
    roop.append(range(v))
for i in itertools.product(*roop):
    res += calc_m(i)
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())

ans = 0
for i in range(1,n):
    if (n-i)/i > i:
        if (n-i)%i == 0:
            ans += (n-i)/i
    else:
        break
print(int(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

Submission status: Runtime Error

Solution code:
for i in range(1,N//4):
    if (N//i) == N%i:
        ans += i
for i in range(N//4,N//3):
    if (N//i) == N%i:
        ans += i
for i in range(N//3,N//2):
    if (N//i) == N%i:
        ans += i
for i in range(N//2,N):
    if (N//i) == N%i:
        ans += i
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

ans = 0
u = 2
sosu_f = True

tamesi = N**(1/2)

for i in range(1,tamesi+1):
    if N%i == 0:
        sosu_f = False



#試し割り方で計算量削減

for i in range(1,N):
    if sosu_f:
        break
    if N//i == N %i:
        u = N//i
        ans += i
        break

# print(u)

for i in range(1,u):
    if N%i == 0:
        ans += (N//i-1)



print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

ans = 0
u = 2
sosu_f = True

tmesi = N**(1/2)

for i in range(1,tamesi+1):
    if N%i == 0:
        sosu_f = False
        


#試し割り方で計算量削減

for i in range(1,N):
    if sosu_f:
        break
    if N//i == N %i:
        u = N//i
        ans += i
        break

# print(u)

for i in range(1,u):
    if N%i == 0:
        ans += (N//i-1)



print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
m = 0

for m in range(n):
    if n/m == n%m:
        sum += m
print(m)

Submission status: Runtime Error

Solution code:
N = int(input())

import math
from collections import defaultdict
from itertools import product
#試し割法
def trial_division(n):
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    if not factor:
        return 'prime number'
    else:
        factor.append(n)
        return factor

fac = trial_division(N)
dic = defaultdict(int)
for n in fac:
    if n != 1:
        dic[n] += 1

a = []
for k, v in dic.items():
    a.append([k**j for j in range(v+1)])

tmp = list(product(*a))

ans = 0
for t in tmp:
    b = 1
    for j in t:
        b *= j
    if b >= 2:
        xx, yy = divmod(N, b-1)
        if xx == yy:
            ans += b - 1

print(ans)

Submission status: Runtime Error

Solution code:
'''
C - AB Substrings
'''

str_list = []
end_a = []
start_b = []
ab_num = 0
for i in range(int(input())):
    str_list.append(input())
    if 'AB' in str_list[-1]:
        ab_num += 1
    if str_list[-1].endswith('A'):
        end_a.append(i)
    if str_list[-1].startswith('B'):
        start_b.append(i)

if end_a == start_b:
    ab_num += min(len(end_a), len(start_b)) - 1
else:
    ab_num += min(len(end_a), len(start_b))

print(ab_num)

Submission status: Runtime Error

Solution code:
N = int(input())

result = 0
for m in range(N):
    if N // m == N % m:
        result += m

print(result)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = list()
counter = {
    'ab': 0,
    'begin_b': 0,
    'end_a': 0,
    'b_to_a': 0
}

for i in range(n):
    substr = input()
    counter['ab'] += substr.count('AB')
    if substr.startswith('B'):
        if substr.endswith('A'):
            counter['b_to_a'] += 1
        else:
            counter['begin_b'] += 1
    else:
        if substr.endswith('A'):
            counter['end_a'] += 1

total = counter['ab'] + min(counter['begin_b'], counter['end_a'])
if counter['b_to_a'] > 0:
    total += (counter['b_to_a'] - 1)
    if max(counter['begin_b'], counter['end_a']) > 0:
        total += 1

print(total)

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[17]:

import sys
#input = sys.stdin.readline
N = int(input())


# In[3]:

import numpy as np


# In[ ]:

sum_ = 0
a = np.arange(1, N)
#print(a)
print(np.sum(a[N//a==N%a]))
#print(a)
#for m in range(1, (N-2)//2):
#    if (N-m)%m==0:
#        print(m)
#        sum_ += (N-m)/m
#print(sum_)


# In[ ]:

Submission status: Runtime Error

Solution code:
def solve(N):
    s = 1
    e = int(pow(N, 0.5)) + 1
    ds = []
    for i in range(s, e):
        if N % i == 0:
            m = N // i - 1
            if N // m == N % m:
                ds.append(N // i)

    return sum([i - 1 for i in ds])

if __name__ == "__main__":
    N = int(input())
    print(solve(N))

Submission status: Runtime Error

Solution code:

def solve(x):
    if(x==0):
        return 0
    k=1
    s=0
    while True:
        if(x%k==0):
            i=(x//k)-1
            if (x//i==x%i):
                s+=i
        k+=1
        if k*k>x:
            break
    return s
        

x=int(input())
print(solve(x))

Submission status: Runtime Error

Solution code:
import math

N = int(input())

ans = 0
for i in range(1, int(math.sqrt(N)) + 1):
  tmp = int((N - i) / i)
  if (N - i) % i == 0 and N % tmp != 0 and tmp >= math.sqrt(N):
    ans += tmp

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

import math
i=0
prime = []
while 2**i<math.sqrt(N):
    j = 0
    while 2**i*5**j < math.sqrt(N):
        prime.append(2**i*5**j)
        j += 1
    i += 1
prime = sorted(prime)

cnt = 0
ret = []
m = N//(prime[cnt])
while m>0:
    if N//m==N%m:
        ret.append(m)
#         print(m,N//m, N%m)
        cnt += 1
        if len(prime) > cnt:
            while N//(prime[cnt]) > m:
                cnt += 1
            m = N//(prime[cnt])-1
#             print(m)
        else:
            m = 0
    else:
        m-=1
        
sum(ret)

Submission status: Runtime Error

Solution code:
a=int(input())  #数値入力
fav = 0
for i in range(1,int(math.sqrt(a))):
#     print(i)
    if a%i ==0:
        fav += i
        fav += a/i + 1
print(int(fav))

Submission status: Runtime Error

Solution code:
import numpy as np
def eratosthenes(n):
    is_prime = np.ones((n+1,), dtype=bool)
    is_prime[:2] = False
    for i in range(2,n+1):
        if is_prime[i]:
            is_prime[i*2::i]=False
    return np.arange(n+1)[is_prime]
Ps = eratosthenes(1000007)
def divisor(n):
    for p in Ps:
        if p*p>n:return -1
        if n%p==0:return p
def prime_division(n):
    d={}
    while n>1:
        p=divisor(n)
        if p==-1:d[n]=d.get(n,0)+1;break
        else:d[p]=d.get(p,0)+1;n//=p
    return d

def z(n,k,v):
    if len(k)==1:
        return [n*k[0]**i for i in range(v[0]+1)]
    else:
        r=[]
        for i in range(v[0]+1):
             r+=z(n*k[0]**i,k[1:],v[1:])
        return r
def y(n):
    pd=prime_division(n)
    KV=[[k,v] for k,v in pd.items()]
    K=[k for k,v in KV]; V=[v for k,v in KV]
    return z(1,K,V)

N=int(input())
r=0
#print(y(N))
for yakusu in y(N):
    if yakusu>N//yakusu and yakusu>1:
        r+=yakusu-1
print(r)

Submission status: Runtime Error

Solution code:
n=int(input())
ans=0
while(True):
  if (n-i)/i<=i:
    break
  if (n-i)%i==0:
    a=int((n-i)/i)
    ans+=a
    i+=1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

ans = 0


for i in range(1,N):
    if N//i == N %i:
        u = N//i
        ans += i
        break

# print(u)

for i in range(1,u):
    if N%i == 0:
        ans += (N//i-1)



print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

sum = 0

b = 0
for i in range(1,N):
    N2 = int(N/i)
    if int(N/(N2-1)) != i:
        b += 1
        if b > 1000000:
            break
    else:
        if N%(N2-1) == i:
            sum += N2-1

print(sum)