qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
s = [input() for _ in range(N)]
num_a = 0
num_b = 0
num_ba = 0
num_ab = 0
for i in s:
    if(i[-1]=='A' and i[0]=='B'):
        num_ba += 1
    elif(i[-1]=='A'):
        num_a+=1
    elif(i[0]=='B'):
        num_b+=1
    last = ''
    for k in i:
        if(k=='A'):
            last = 'A'
        elif(last == 'A' and k=='B'):
            num_ab += 1
            last = ''
        else:
            last = ''
num_conn = min(num_a,num_b)
if(num_ba>0 and num_a!=num_b):
    print(num_ab+num_ba+num_conn)
else:
    print(num_ab+num_ba+num_conn-1)


Fixed code:
N = int(input())
s = [input() for _ in range(N)]

ans = 0
num_a = 0
num_b = 0
num_ba = 0
num_ab = 0
for i in s:
    if(i[-1]=='A' and i[0]=='B'):
        num_ba += 1
    elif(i[-1]=='A'):
        num_a+=1
    elif(i[0]=='B'):
        num_b+=1
    last = ''
    for k in i:
        if(k=='A'):
            last = 'A'
        elif(last == 'A' and k=='B'):
            num_ab += 1
            last = ''
        else:
            last = ''

ans += num_ab

num_conn = min(num_a,num_b)
if(num_a!=num_b and num_ba!=0):
    ans+=num_ba+num_conn
elif(num_ba==0):
    ans+=num_conn
elif(num_a==0 and num_b==0):
    ans+=num_ba-1
else:
    ans+=num_ba+num_conn
print(ans)
Buggy code:
import math

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

Fixed code:
import math

N = int(input())
ans = 0
sqi = math.sqrt(N)
for i in range(1, int(sqi)+1):
    if (N-i)%i == 0:
        m = (N-i)//i
        if m > 0:
        	if N//m == N%m:
        		ans += (N-i)//i
print(ans)
Buggy code:
import math
 
N = int(input())
d_list = []
 
for i in range(1, int(math.sqrt(N)) + 1):
  if N % i == 0:
    d_list.append(i)
    if i != math.sqrt(N):
      d_list.append(N / i)
 
output = sum(d_list) - 3 - (len(d_list) - 2)
print(int(output))

Fixed code:
import math
 
N = int(input())
d_list = []
 
for i in range(1, int(math.sqrt(N)) + 1):
  if N % i == 0:
    if i != 1:
      if (N // (i - 1)) == (N % (i - 1)):
        d_list.append(i)
    if i != math.sqrt(N):
      if (N // (N / i - 1)) == (N % (N / i - 1)):
        d_list.append(N / i)
 
output = sum(d_list) - len(d_list)
print(int(output))
Buggy code:
n = int(input())

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

Fixed code:
n = int(input())

imax = int(n**(1/2))+1
cnt = 0
for i in range(1,imax):
    if (n-i)%i == 0:
        if i >= (n-1)//i:
            continue
        cnt += (n-i)//i
print(cnt)
Buggy code:
N = int(input())
ans = 0
for i in range(1,int(N**(0.5))):
    if N%i == 0:
        ans += N//i -1
print(ans)

Fixed code:
N = int(input())
ans = 0
for i in range(1,int(N**(0.5))+1):
    if N%i == 0 and N//i > i+1:
        ans += N//i - 1
print(ans)
Buggy code:
def divisor(n):
    A = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            if n//i == i:
                A.append(i)
            else:
                A.append(i)
                A.append(n//i)
    A = [a-1 for a in A if a > 2]
    return A

n = int(input())
ans = sum(divisor(n))
print(ans)

Fixed code:
def divisor(n):
    A = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            if n//i == i:
                A.append(i)
            else:
                A.append(i)
                A.append(n//i)
    A = [a for a in A if a > 2]
    return A

n = int(input())
A = divisor(n)
ans = 0
for a in A:
    i,j = divmod(n,a-1)
    if i == j:
        ans += a-1
print(ans)
Buggy code:
from sys import stdin
import numpy as np
# import math
# import random
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]

N = int(stdin.readline().rstrip().split()[0])

sqrtN = int(np.sqrt(N))
ans = 0
for i in range(1,sqrtN+1):
  if N%i == 0:
    ans += N//i -1
    
print(ans)


Fixed code:
from sys import stdin
import numpy as np
# import math
# import random
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]

N = int(stdin.readline().rstrip().split()[0])

sqrtN = int(np.sqrt(N))
ans = 0
for i in range(1,sqrtN+1):
  if N%i == 0:
    if N//i - 1 > i:
      ans += N//i -1
    
print(ans)
Buggy code:
N=int(input())
if N==1 or N==2:
    print(0)
    quit()
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(N)
list=[1]
for fact,num in table.items():
    list_=[]
    for k in range(num+1):
        list_.extend([i*fact**k for i in list])
    list=list_
list.sort()
ans=0
for i in range(len(list)):
    if i==0:
        continue
    if list[i-1]+1==list[i]:
        continue
    m=list[i]-1
    if N//m==N%m:
        ans+=list[i]-1
print(ans)


Fixed code:
from collections import defaultdict
N=int(input())
if N==1 or N==2:
    print(0)
    quit()
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(N)
list=[1]
for fact,num in table.items():
    list_=[]
    for k in range(num+1):
        list_.extend([i*fact**k for i in list])
    list=list_
list.sort()
ans=0
for i in range(len(list)):
    if i==0:
        continue
    if list[i-1]+1==list[i]:
        continue
    m=list[i]-1
    if N//m==N%m:
        ans+=list[i]-1
print(ans)
Buggy code:
def make_divisors(n):
    lw, up = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lw.append(i)
        if i * i != n:
            up.append(n//i)
        i += 1
    return lw + up[::-1]

N = int(input())
ans = 0
li = make_divisors(N)

for x in li:
    if x * x > N:
        break
    ans += N//x - 1
print(ans)


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

N = int(input())
ans = 0
li = make_divisors(N)
if N == 1 or N==2:
    print(0)
    exit()

for x in li:
    if x * (x+2) > N:
        break
    ans += N//x - 1
print(ans)
Buggy code:
def calc(N):
    L=[]
    for i in range(1,int(N**0.5) + 1):
        if(N%i==0):
            L.append(i)
            if(N//i>i):
                L.append(N//i)
    L=sorted(L)
    return L

N=int(input())
L=calc(N)
s=0
for num in L:
    if(num<=2):
        continue
    s+=(num-1)

print(s)


Fixed code:
def calc(N):
    L=[]
    for i in range(1,int(N**0.5) + 1):
        if(N%i==0):
            L.append(i)
            if(N//i>i):
                L.append(N//i)
    L=sorted(L)
    return L

N=int(input())
L=calc(N)
s=0
for num in L:
    if(num<=2):
        continue
    if(N//(num-1)==N%(num-1)):
        s+=(num-1)

print(s)
Buggy code:
N=int(input())

def make_divisors(n):
    divisors=[]
    for i 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

ans=0
divisors=make_divisors(N)

for d in divisors:
    m=(d-1)
    if m and (N//m==N%m):
        ans+=m

print(ans)

Fixed 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
divisors = make_divisors(N)
ans = 0
for d in divisors:
    t = d - 1
    if t != 0 and N % t == N // t:
        ans += t
print(ans)
Buggy code:
def main():
    n = int(input().rstrip())
    sqrt_n = int(sqrt(n))

    total = 0
    for number in range(1,sqrt_n + 1):
        if n % number > 0:
            continue
        remain = n - number
        x, y = divmod(remain, number)
        #print(x, y, remain, number)
        if y == 0 and x > number:
            #print("○",number)
            total += x
        #elif y == 0:
        #    print("×",number)

    print(total)

if __name__ == "__main__":
  main()


Fixed code:
from math import sqrt
def main():
    n = int(input().rstrip())
    sqrt_n = int(sqrt(n))

    total = 0
    for number in range(1,sqrt_n + 1):
        if n % number > 0:
            continue
        remain = n - number
        x, y = divmod(remain, number)
        #print(x, y, remain, number)
        if y == 0 and x > number:
            #print("○",number)
            total += x
        #elif y == 0:
        #    print("×",number)

    print(total)

if __name__ == "__main__":
  main()
Buggy code:
N = int(input())
tmp = N ** 0.5
sum = 0
k =1
while k < tmp:
    m = N // k -1 
    if N % k == 0 and m > tmp-1 and k < m: 
        sum += m
    k += 1

Fixed code:
N = int(input())
tmp = N ** 0.5
sum = 0
k =1
while k < tmp:
    m = N // k -1 
    if N % k == 0 and m > tmp-1 and k < m: 
        sum += m
    k += 1
print(sum)
Buggy code:
import math
N = int(input())
n = int(math.sqrt(N))
ans = 0
for x in range(2, n+1):
    m = N // x - 1
    if N % x == 0 and x == N % m:
        ans += m
print(ans)

Fixed 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 m > 0 and N % x == 0 and x == N % m:
        ans += m
print(ans)
Buggy code:
n=int(input())
a=0
for i in range(2,int(n**.5+1)):t=n//i-1;a+=t*(i==n%t)
print(a)

Fixed code:
n=int(input())
a=0
for i in range(1,int(n**.5+1)):t=n//i-1;a+=t*(t and i==n%t)
print(a)
Buggy code:
def main():
    n = int(input())
    res = 0
    if n<=8:
        for i in range(1,n):
            if n//i == n%i:
                res += n%i
    else:
        for i in range(1,int(n**(1/2))+1):
            if (n-i)/i == (n-i)//i and (n-i)//i>0:
                res += (n-i)//i 
    print(res)
if __name__ == '__main__':
    main()

Fixed code:
def main():
    n = int(input())
    res = 0
    if n<=8:
        for i in range(1,n):
            if n//i == n%i:
                res += i
    else:
        for i in range(1,int(n**(1/2))):
            if (n-i)/i == (n-i)//i and (n-i)//i>0:
                res += (n-i)//i
    print(res)
if __name__ == '__main__':
    main()
Buggy code:
import math 
N = int(input())
ans = 0

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

Fixed code:
import math 
N = int(input())
ans = 0

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

print(ans)
Buggy code:
n = int(input())

ans = 0


i = 1
while i * i <= n:
    if n % i == 0:
        if n // (i-1) == n % (i-1):
            ans += n // i - 1
    i += 1

print(ans)

Fixed code:
n = int(input())

ans = 0


i = 1
while i * i < n:
    if n % i == 0:
        m = n // i - 1
        if m > i:
            ans += m
    i += 1

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

Fixed code:
n=int(input())
c=0
for i in range(1,int(n**.5)+1):
  if n%i==0:
    if n//i-i>1:
      c+=n//i-1
print(c)
Buggy code:
import math

N = int(input())

total = 0


for i in range(1,int(math.sqrt(N))):
    amari = i
    if N % amari == 0:
        total += N//amari - 1
        #print(amari)

print(total)

Fixed code:
import math

N = int(input())

total = 0
   
if N != 1:        
    for i in range(1,int(math.sqrt(N)+1)):
        amari = i
        if N % amari == 0:
            k = N // amari - 1
            if amari == N % k:
                total += N//amari - 1
        #print(amari)

print(total)
Buggy code:
import math

m = int(input())


s = []
for i in range(math.floor(math.sqrt(m))+3):
	if m%(i+1)==0:
		if (i+1) not in s:
			s.append(i+1)
		if m//(i+1) not in s:
			s.append(m//(i+1))
s.sort()
x =0
if len(s)%2 == 1:
    for i in range(len(s)//2+1):
        x += m//s[i]-1

    print(x)
else:
    for i in range(len(s)//2):

        x += m//s[i]-1

    print(x)

Fixed code:
import math

m = int(input())


s = []
for i in range(math.floor(math.sqrt(m))+3):
	if m%(i+1)==0:
		if (i+1) not in s:
			s.append(i+1)
		if m//(i+1) not in s:
			s.append(m//(i+1))
s.sort()
x =0
for i in range(len(s)):
    if m//s[i]>s[i]+1:
        x += m//s[i]-1
print(x)
Buggy code:
import sys
from collections import *
import heapq
import math
from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())

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

Fixed code:
import sys
from collections import *
import heapq
import math

import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())

ans=0
# cnt=0
if n==1:
    print(0)
    quit()
for i in range(int(n**0.5)):
    x=(n-(i+1))//(i+1)
    if n//x==n%x:
        ans+=x
    # print(n//cnt,cnt)
print(ans)
Buggy code:
N=int(input())
ans = 0
for m in range(1,int(N**0.5)):
    if N % m == 0:
        ans += N // m - 1
print(ans)

Fixed code:
N = int(input())
ans = 0
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        m = N // i - 1
        if m and N // m == N % m:
            ans += m
print(ans)
Buggy code:
N=int(input())
ans=0
M=math.ceil(N**0.5+2)
for i in range(1,M):
    if N%i==0 and N//i-i>1: ans+=N//i-1

print(ans)

Fixed code:
import math

N=int(input())
ans=0
M=math.ceil(N**0.5+2)
for i in range(1,M):
    if N%i==0 and N//i-i>1: ans+=N//i-1

print(ans)
Buggy code:
n=int(input())
l=[]
if n==1 or n==2:
    print(0)
    exit()
for i in range(1,int(n**0.5)+1):
    if n%i==0 and i!=n//i:
        l.append(n//i)
print(l)
print(sum(l)-len(l))

Fixed code:
n=int(input())
l=[]
if n==1 or n==2:
    print(0)
    exit()
for i in range(1,int(n**0.5)+1):
    if n%i==0 and n//i-i>1:
        l.append(n//i)

print(sum(l)-len(l))
Buggy code:
N = int(input())

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

Fixed code:
N = int(input())

lim = int(N**0.5) + 1
ans = 0
for i in range(1, lim):
    if N % i == 0:
        m = N // i - 1
        if i < m:
            ans += m
print(ans)
Buggy code:
n=int(input())
ct=0
for i in range(1,int(n**0.5)):
  if (n-i)%i==0:
    ct+=(n-i)//i
print(ct)

Fixed code:
n=int(input())
if n==1:
  print(0)
else:
  ct=0
  for i in range(1,int(n**0.5)):
    if (n-i)%i==0:
      ct+=(n-i)//i
  if (n-int(n**0.5))%int(n**0.5)==0:
    x=(n-int(n**0.5))//int(n**0.5)
    if n//x==n%x:ct+=x
  print(ct)
Buggy code:
def sample_code(N):

 #   print('Prime factor')
    fct = factorize(N)
 #   print(fct,num(fct))

 #   print('divisor')
    for div in divisorize(fct):
        continue
 #       print(div,num(div))


def divisorize(fct):
    b,e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b,k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

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

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
        divisor_list.append(a)
    return a

N = int(input())
sum_m = 0
divisor_list = []
sample_code(N)
divisor_list = list(set(divisor_list))

for c in divisor_list:
    if c != 1 and c!= 2:
        if N // (c-1) >= (c-1):
            continue
        else:
            sum_m += c - 1

print(sum_m)

Fixed code:
def sample_code(N):

 #   print('Prime factor')
    fct = factorize(N)
 #   print(fct,num(fct))

 #   print('divisor')
    for div in divisorize(fct):
        b = num(div)


def divisorize(fct):
    b,e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b,k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

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

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
        divisor_list.append(a)
    return a

N = int(input())
sum_m = 0
divisor_list = []
if N == 1:
    print(0)
else:
    sample_code(N)
    divisor_list = list(set(divisor_list))

    for c in divisor_list:
        if c != 1 and c!= 2:
            if N // (c-1) >= (c-1):
                continue
            else:
                sum_m += c - 1

    print(sum_m)
Buggy code:
n = int(input())

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

Fixed code:
n = int(input())

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

print(ans)
Buggy code:
import math
n=int(input())

x=n**0.5
x=int(x//1)

y=0

for i in range(1,x+1):
    if (n-i)/i-(n-i)//i==0:
        y+=int((n-i)//i)

print(y)
        

     

    


Fixed code:
import math
n=int(input())

x=n**0.5

if x-x//1!=0:
    x=int(x//1)
else:
    x=int(x//1)-1
y=0

for i in range(1,x+1):
    if (n-i)/i-(n-i)//i==0:
        if int((n-i)//i)!=i:
            y+=int((n-i)//i)

print(y)
Buggy code:
N = int(input())

# t = []
# for i in range(1, N+1):
#     if N // i == N % i:
#         print("→ :", i)
#         t.append(i)
#     else:
#         print("  :", i)

# print("G:", sum(t))

ans = (N-1) if N != 2 else 0
cur = 2
while (N-cur)//cur >= cur:
    if (N-cur)%cur == 0 and N % cur != 0:
        ans += (N-cur)//cur
        # print("::", (N-cur)//cur, cur)
    cur += 1
    # print(ans)

print(ans)

Fixed code:
N = int(input())

# t = []
# for i in range(1, N+1):
#     if N // i == N % i:
#         print("→ :", i)
#         t.append(i)
#     else:
#         print("  :", i)

# print("G:", sum(t))

ans = (N-1) if N != 2 else 0
cur = 2
while (N-cur)//cur >= cur:

    if (N-cur)%cur == 0:
        a = (N-cur)//cur
        if N%a!=0:
            ans += (N-cur)//cur
    cur += 1

print(ans)
Buggy code:
n = int(input())
s = set()

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



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

for i in range(1,int(n**0.5)+1):
    if n//i == n%i:
        s.add(i)
    x = (n-i)//i
    if x and n//x == n%x:
        s.add(x)
print(sum(list(s)))
Buggy code:
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

n = ni()
a = 0
b = math.ceil(math.sqrt(n))

for i in range(1,b+1):
    if n%i == 0:
        a += n//i-1

print(a)

Fixed code:
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

n = ni()
a = 0
b = math.ceil(math.sqrt(n))

for i in range(1,b+1):
    if n%i == 0:
        c = n//i-1
        a = a if c <= i else a+c

print(a)
Buggy code:
N = int(input())
count = 0 
X = 0
q = 1
while N >= X:
    if N%q==0 and N/q-1<N:
        count += N/q-1
    q += 1
    X = (q+1)*q+q
print(count)

Fixed code:
N = int(input())
count = 0 
X = 0
q = 1
while N >= X:
    if N%q==0 and N/q-1<N and N/q-1!=1:
        count += N/q-1
    q += 1
    X = (q+1)*q+q
print(int(count))
Buggy 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)
    divisors.sort()
    return divisors
  
ans=0
count=1
factor=make_divisors(N)

#print(factor)

for f in factor:
  if f<N//2:
    ans+=(N-f)//f
  #print(ans,(N-f//f))
print(ans)

Fixed 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)
    divisors.sort()
    return divisors
  
ans=0
count=1
factor=make_divisors(N)

#print(factor)
factor.remove(N)
for f in factor:
  if f==N%((N-f)//f):
    ans+=(N-f)//f
print(ans)
Buggy code:
import math
val = int(input())
res = 0
current = 1
while True:
    rest = val - current
    plus = math.floor(rest / current)
        
    if rest % current == 0:
        if plus * current + current == val:
            res += plus
    if current * current + current >= val:
        break
    current += 1
print(str(res))

Fixed code:
import math
val = int(input())
res = 0
current = 1
while True:
    rest = val - current
    plus = math.floor(rest / current)
    if plus == 0:
        break

    if math.floor(val / plus) == val % plus:
        res += plus
    if current * current + current >= val:
        break
    current += 1
print(str(res))
Buggy code:
def f(n):
    x = 1
    ans = 0
    while x ** 2 - x < n:
        if n % x == 0:
            ans += n // x - 1
        x += 1
    print(ans)

n = int(input())
f(n)


Fixed code:
def f(n):
    x = 1
    ans = 0
    while x ** 2 + x < n:
        if n % x == 0:
            ans += n // x - 1
        x += 1
    print(ans)

n = int(input())
f(n)
Buggy code:
import math
n = int(input())
ans = 0

if n == 1:
    print(1)
    exit()


for i in range(1, int(n**0.5)):
    n2 = n - i
    if n2 % i == 0:
        #print(n2+i , n/(n2/i), i)
        try:
            if abs(n/(n2/i) - i) < 1:
                ans += math.ceil(n2 / i)
        except:
            pass
print(ans)


Fixed code:
import math
n = int(input())
ans = 0



for i in range(1, int(n**0.5)+1):
    n2 = n - i

    if n2 % i == 0:
        #print(i, n2 / i)
        #print(n2+i , n//(n2//i), i)

        try:
            if n//(n2//i) == i:
                ans += math.ceil(n2 / i)
        except:
            pass

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

print(ans)


Fixed 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)
Buggy code:
n = int(input())
ans = 0
for i in range(1, int(n ** 0.5)):
    if n % i == 0:
        k = (n // i) - 1
        ans += k
print(ans)

Fixed code:
n = int(input())
ans = 0
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        k = (n // i) - 1
        if k > i:
            ans += k
print(ans)
Buggy code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Fixed code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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