Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    S = input().rstrip()
    counter = defaultdict(int)
    mod = 2019
    counter[0] += 1
    num = 0
    for i, c in enumerate(S[::-1]):
        num += int(c) * (10**(i)%mod)
        num %= mod
        counter[num] += 1
    ans = 0
    for v in counter.values():
        ans += (v * (v-1)) // 2
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    S = input().rstrip()
    counter = defaultdict(int)
    mod = 2019
    counter[0] += 1
    num = 0
    d = 1
    for c in S[::-1]:
        num += int(c) * d
        num %= mod
        counter[num] += 1
        d *= 10
        d %= mod
    ans = 0
    for v in counter.values():
        ans += (v * (v-1)) // 2
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    S = reversed(list(input().rstrip()))
    counter = defaultdict(int)
    mod = 2019
    counter[0] += 1
    num = 0
    for i, c in enumerate(S):
        num += int(c) * 10**(i)
        counter[num%mod] += 1
    ans = 0
    for v in counter.values():
        ans += (v * (v-1)) // 2
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    S = input().rstrip()
    counter = defaultdict(int)
    mod = 2019
    counter[0] += 1
    num = 0
    d = 1
    for c in S[::-1]:
        num += int(c) * d
        num %= mod
        counter[num] += 1
        d *= 10
        d %= mod
    ans = 0
    for v in counter.values():
        ans += (v * (v-1)) // 2
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    S = int(input())
    counter = defaultdict(int)
    mod = 2019
    counter[0] += 1
    for i in range(200001):
        x = S % (10**(i+1))
        counter[x%mod] += 1
        if x == S:
            break
    ans = 0
    for v in counter.values():
        ans += (v * (v-1)) // 2
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    S = input().rstrip()
    counter = defaultdict(int)
    mod = 2019
    counter[0] += 1
    num = 0
    d = 1
    for c in S[::-1]:
        num += int(c) * d
        num %= mod
        counter[num] += 1
        d *= 10
        d %= mod
    ans = 0
    for v in counter.values():
        ans += (v * (v-1)) // 2
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

K = int(input())
gcd_v = {}
def gcd(numbers):
    tuple_n = tuple(sorted(numbers))
    try:
        return gcd_v[tuple_n]
    except:
        gcd_v[tuple_n] = reduce(math.gcd, numbers)
        return gcd_v[tuple_n]

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd([a, b, c])

print(ans)


Fixed submission:
import math
from functools import reduce

K = int(input())
def gcd(numbers):
        res = reduce(math.gcd, numbers)
        n = len(set(numbers))
        if n == 1:
            return res
        elif n == 2:
            return res * 3
        else:
            return res * 6

ans = 0
for a in range(1, K+1):
    for b in range(a, K+1):
        for c in range(b, K+1):
            ans += gcd([a, b, c])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

mod = 10 ** 9 + 7

memo = [0] * (K + 1)
ans = 0
for i in range(K, 0, -1):
    tmp = (K // i) ** N
    j = 2
    while i * j <= K:
        tmp -= memo[i * j]
        j += 1
    memo[i] = tmp
ans = 0
for i in range(1, K+1):
    ans += (memo[i] * i) % mod
    ans %= mod

print(ans)


Fixed submission:
N, K = map(int, input().split())

mod = 10 ** 9 + 7

memo = [0] * (K + 1)
ans = 0
for i in range(K, 0, -1):
    memo[i] = pow(K // i, N, mod)
    j = 2
    while i * j <= K:
        memo[i] -= memo[i * j]
        j += 1
    ans += memo[i] * i
    ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
exact_counter = {}
for v, n in counter.items():
    if n != 1:
        exact_counter[v] = n

for k in range(N):
    a = A[k]
    ans = 0
    for v, n in exact_counter.items():
        if a == v:
            n -= 1
        ans += n * (n - 1) // 2
    print(ans)


Fixed submission:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dict = defaultdict(int)
ans = 0
for k in range(N):
    a = A[k]
    ans += dict[a]
    dict[a] += 1

for k in range(N):
    a = A[k]
    print(ans - dict[a] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
done = [[10**4 + 1]*(W) for _ in range(H)]

min_count = 10 ** 4 + 1

def dfs(h, w, before_black, count):
    if maze[h][w] == "#":
        is_black = True
        if not before_black:
            count += 1
    else:
        is_black = False
    if done[h][w] < count:
        return
    done[h][w] = count
    if h == H-1 and w == W-1:
        global min_count
        if count < min_count:
            min_count = count
    elif h == H-1:
        dfs(h, w+1, is_black, count)
    elif w == W-1:
        dfs(h+1, w, is_black, count)
    else:
        dfs(h+1, w, is_black, count)
        dfs(h, w+1, is_black, count)

dfs(0,0,False,0)

print(min_count)


Fixed submission:
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
done = [[10**4 + 1]*(W) for _ in range(H)]

min_count = 10 ** 4 + 1

def dfs(h, w, before_black, count):
    if maze[h][w] == "#":
        is_black = True
        if not before_black:
            count += 1
    else:
        is_black = False
    if done[h][w] <= count:
        return
    done[h][w] = count
    if h == H-1 and w == W-1:
        global min_count
        if count < min_count:
            min_count = count
    elif h == H-1:
        dfs(h, w+1, is_black, count)
    elif w == W-1:
        dfs(h+1, w, is_black, count)
    else:
        dfs(h+1, w, is_black, count)
        dfs(h, w+1, is_black, count)

dfs(0,0,False,0)
print(min_count)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]

min_count = 10 ** 4 + 1

def dfs(h, w, before_black, count):
    if maze[h][w] == "#":
        is_black = True
        if not before_black:
            count += 1
    else:
        is_black = False
    if h == H-1 and w == W-1:
        global min_count
        if count < min_count:
            min_count = count
    elif h == H-1:
        dfs(h, w+1, is_black, count)
    elif w == W-1:
        dfs(h+1, w, is_black, count)
    else:
        dfs(h+1, w, is_black, count)
        dfs(h, w+1, is_black, count)

dfs(0,0,False,0)

print(min_count)


Fixed submission:
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
done = [[10**4 + 1]*(W) for _ in range(H)]

min_count = 10 ** 4 + 1

def dfs(h, w, before_black, count):
    if maze[h][w] == "#":
        is_black = True
        if not before_black:
            count += 1
    else:
        is_black = False
    if done[h][w] <= count:
        return
    done[h][w] = count
    if h == H-1 and w == W-1:
        global min_count
        if count < min_count:
            min_count = count
    elif h == H-1:
        dfs(h, w+1, is_black, count)
    elif w == W-1:
        dfs(h+1, w, is_black, count)
    else:
        dfs(h+1, w, is_black, count)
        dfs(h, w+1, is_black, count)

dfs(0,0,False,0)
print(min_count)
Buggy python submission (verdict: Runtime Error):
N = int(input())

dic = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

old = ["a"]
new = []
for i in range(1, N):
    for word in old:
        for j in range(i+1):
            if word[-1] == dic[j] or word[-1] == dic[j-1]:
                new.append(word+dic[j])
    old = new.copy()
    new = []
for i in old:
    print(i)


Fixed submission:
N = int(input())

S = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

def dfs(s, i):
    if len(s) == N:
        return [s]
    result = []
    for j in range(i+1):
        if j == i:
            result += dfs(s+S[j], i+1)
        else:
            result += dfs(s+S[j], i)
    return result
print("\n".join(dfs("", 0)))

Buggy python submission (verdict: Runtime Error):
N = int(input())

dic = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

old = ["a"]
new = []
for i in range(1, N):
    print(old)
    for word in old:
        for j in range(i+1):
            if word[-1] == dic[j] or word[-1] == dic[j-1]:
                new.append(word+dic[j])
    old = new.copy()
    new = []
for i in old:
    print(i)


Fixed submission:
N = int(input())

S = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

def dfs(s, i):
    if len(s) == N:
        return [s]
    result = []
    for j in range(i+1):
        if j == i:
            result += dfs(s+S[j], i+1)
        else:
            result += dfs(s+S[j], i)
    return result
print("\n".join(dfs("", 0)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
Q = int(input())

for _ in range(Q):
    type, x, y = input().split()
    if type == "1":
        x = int(x)
        S[x-1] = y
    else:
        x = int(x)
        y = int(y)
        print(len(set(S[x-1:y])))


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    from bisect import bisect_left, insort_left
    N = int(input())
    S = list(input())
    Q = int(input())
    dic = {chr(i): [] for i in range(ord('a'), ord('z')+1)}
    for i in range(N):
        dic[S[i]].append(i)
    for _ in range(Q):
        query, a, c = input().split()
        if query == "1":
            i = int(a)-1
            if S[i] == c:
                continue
            ind = bisect_left(dic[S[i]], i)
            dic[S[i]].pop(ind)
            insort_left(dic[c], i)
            S[i] = c
        else:
            l, r = int(a)-1, int(c)-1
            ans = 0
            for inds in dic.values():
                if inds and l <= inds[-1] and inds[bisect_left(inds, l)] <= r:
                    ans += 1
            print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
expected_value_dic = {}

def get_expected_value(x):
    return (1 + x) / 2

n, k = map(int, input().split())

P = list(map(int, input().split()))
expected_values = [get_expected_value(p) for p in P]

selected_array = [expected_values[i] for i in range(k)]
max_sum = sum(selected_array)
for i in range(k, len(P)):
    del selected_array[0]
    selected_array.append(expected_values[i])
    array_sum = sum(selected_array)
    if array_sum > max_sum:
        max_sum = array_sum


print(max_sum)


Fixed submission:
expected_value_dic = {}

def get_expected_value(x):
    return (1 + x) / 2

n, k = map(int, input().split())

P = list(map(int, input().split()))
expected_values = [get_expected_value(p) for p in P]
cumulative_values = [expected_values[0]]
for expected_value in expected_values[1:]:
    cumulative_values.append(cumulative_values[-1] + expected_value)

result = cumulative_values[k-1]
for i in range(k, n):
    temp = cumulative_values[i] - cumulative_values[i - k]
    if temp > result:
        result = temp

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
expected_value_dic = {}

def get_expected_value(x):
    if x in expected_value_dic:
        return expected_value_dic[x]
    result = 0
    for i in range(1, x+1):
        result += i / x
    expected_value_dic[x] = result
    return result

n, k = map(int, input().split())

P = list(map(int, input().split()))
expected_values = [get_expected_value(p) for p in P]

selected_array = [expected_values[i] for i in range(k)]
max_sum = sum(selected_array)
for i in range(k, len(P)):
    del selected_array[0]
    selected_array.append(expected_values[i])
    array_sum = sum(selected_array)
    if array_sum > max_sum:
        max_sum = array_sum


print(max_sum)


Fixed submission:
expected_value_dic = {}

def get_expected_value(x):
    return (1 + x) / 2

n, k = map(int, input().split())

P = list(map(int, input().split()))
expected_values = [get_expected_value(p) for p in P]
cumulative_values = [expected_values[0]]
for expected_value in expected_values[1:]:
    cumulative_values.append(cumulative_values[-1] + expected_value)

result = cumulative_values[k-1]
for i in range(k, n):
    temp = cumulative_values[i] - cumulative_values[i - k]
    if temp > result:
        result = temp

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, D, A = map(int, input().split())
monsters = deque(sorted([list(map(int, input().split())) for _ in range(N)]))
ans = 0
while monsters:
    X, H = monsters.popleft()
    if H < 1:
        continue
    attack = (H + A - 1) // A
    ans += attack
    for i, monster in enumerate(monsters):
        if X + 2 * D >= monster[0]:
            monsters[i][1] -= attack * A
        else:
            break
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

def main():
    N, D, A = map(int, input().split())
    monsters = sorted([list(map(int, input().split())) for _ in range(N)])
    
    for i in range(N):
        monsters[i][1] = (monsters[i][1] + A - 1) // A
    
    attacks = deque([]) # [(有効範囲, 攻撃回数)]
    ans = 0
    atk = 0
    for i in range(N):
        atk_this = monsters[i][1]
        while attacks and monsters[i][0] > attacks[0][0]:
            _, atk_ = attacks.popleft()
            atk -= atk_
        if atk_this - atk > 0:
            ans += atk_this - atk
            attacks.append((monsters[i][0]+2*D, atk_this-atk))
            atk += atk_this - atk
    print(ans)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())

for i in range(k):
    if a > 0:
        a -= 1
    elif b > 0:
        b -= 1

print(a, b)


Fixed submission:
a, b, k = map(int, input().split())

if a > k:
    print(a-k, b)
elif a + b > k:
    print(0, a + b - k)
else:
    print(0, 0)
Buggy python submission (verdict: Runtime Error):
import math
from sys import exit
X = int(input())

while True:
    for i in range(2, math.floor(math.sqrt(X) + 1)):
        flag = True
        if X % i == 0:
            flag = False
            break
    if flag:
        print(X)
        exit()
    X += 1


Fixed submission:
import math
from sys import exit
X = int(input())

while True:
    flag = True
    for i in range(2, math.floor(math.sqrt(X) + 1)):
        if X % i == 0:
            flag = False
            break
    if flag:
        print(X)
        exit()
    X += 1
Buggy python submission (verdict: Runtime Error):
from fracitons import gcd
a, b = map(int, input().split())
print((a*b)//gcd(a,b))


Fixed submission:
a, b = map(int, input().split())
if a < b:
    a, b = b, a
A = a
B = b
while a % b != 0:
    a, b = b, a % b
print((A*B)//b)

Buggy python submission (verdict: Runtime Error):
from fracitons import gcd
a, b = map(int, input().split())
print((a*b)//gcd(a,b))


Fixed submission:
a, b = map(int, input().split())
if a < b:
    a, b = b, a
A = a
B = b
while a % b != 0:
    a, b = b, a % b
print((A*B)//b)

Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print((a*b)//math.gcd(a,b))


Fixed submission:
a, b = map(int, input().split())
if a < b:
    a, b = b, a
A = a
B = b
while a % b != 0:
    a, b = b, a % b
print((A*B)//b)

Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print((a*b)//math.gcd(a,b))


Fixed submission:
a, b = map(int, input().split())
if a < b:
    a, b = b, a
A = a
B = b
while a % b != 0:
    a, b = b, a % b
print((A*B)//b)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def bellmanford(G, s, N):
    n = len(G)
    inf = float('inf')
    dist = [inf] * n
    dist[s] = 0
    for i in range(n+1):
        for v in range(n):
            for w, c in G[v]:
                if dist[w] > dist[v] + c:
                    dist[w] = dist[v] + c
                    if i == n and w == N - 1:
                        return False
    return dist

def bellmanford(G, s):
    n = len(G)
    inf = float('inf')
    dist = [inf] * n
    dist[s] = 0
    for i in range(n):
        for v in range(n):
            for w, c in G[v]:
                if dist[w] > dist[v] + c:
                    dist[w] = dist[v] + c
                    if i == n - 1 and w == n - 1:
                        return -1
    return dist

def main():
    N, M, P = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append((b, -c+P))
    ans = bellmanford(G, 0, N)
    if ans:
        print(max(0, -ans[N-1]))
    else:
        print(-1)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def dfs(edges, s):
    use = {s}
    stack = [s]
    while stack:
        v = stack.pop()
        for w in edges[v]:
            if w in use: continue
            use.add(w)
            stack.append(w)
    return use

def bellmanford(num_v, edges, source):
    inf = float('inf')
    dist = [inf] * num_v
    dist[source] = 0
    for i in range(num_v):
        flag = False
        for s, t, cost in edges:
            if dist[s] == inf: continue
            if dist[s] + cost < dist[t]:
                dist[t] = dist[s] + cost
                flag = True
        if not flag: break
    else:
        return False
    return dist

def main():
    N, M, P = map(int, input().split())
    G = [[] for _ in range(N)]
    G_rev = [[] for _ in range(N)]
    edges = []
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G_rev[b].append(a)
        edges.append((a, b, P-c))
    
    use = dfs(G_rev, N-1)
    edges = [(a, b, c) for a, b, c in edges if a in use and b in use]
    dist = bellmanford(N, edges, 0)
    if dist:
        print(max(0, -dist[N-1]))
    else:
        print(-1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N, A, B, C, D = map(int, input().split())
S = list(input())
A -= 1
B -= 1
C -= 1
D -= 1

def check_one_people_can(start, end):
    s = S[start+1: end]
    for x in s:
        if x == "#":
            if before_sharp:
                return False
            before_sharp = True
        else:
            before_sharp = False
    return True

def check_triple_dots(start, end):
    s = S[start-1: end+1]
    continuous_dots = 0
    for x in s:
        if x == ".":
            continuous_dots += 1
            if continuous_dots == 3:
                return True
        else:
            continuous_dots = 0
    return False

if D > C:
    if check_one_people_can(A, C) and check_one_people_can(C, D):
        print("Yes")
    else:
        print("No")
else:
    if check_triple_dots(B, D) and check_one_people_can(A, C):
        print("Yes")
    else:
        print("No")


Fixed submission:
N, A, B, C, D = map(int, input().split())
S = list(input())
A -= 1
B -= 1
C -= 1
D -= 1

def check_one_people_can(start, end):
    s = S[start+1: end]
    before_sharp = False
    for x in s:
        if x == "#":
            if before_sharp:
                return False
            before_sharp = True
        else:
            before_sharp = False
    return True

def check_triple_dots(start, end):
    s = S[start-1: end+2]
    continuous_dots = 0
    for x in s:
        if x == ".":
            continuous_dots += 1
            if continuous_dots == 3:
                return True
        else:
            continuous_dots = 0
    return False

if D > C:
    if check_one_people_can(A, C) and check_one_people_can(C, D):
        print("Yes")
    else:
        print("No")
else:
    if check_triple_dots(B, D) and check_one_people_can(A, C):
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

L, R = map(int, input().split())
ans = set(range(L, R+1))
for _ in range(M-1):
    L, R = map(int, input().split())
    ans = ans & set(range(L, R+1))
print(len(ans))


Fixed submission:
N, M = map(int, input().split())
left, right = map(int, input().split())
for _ in range(M-1):
    L, R = map(int, input().split())
    left = max(left, L)
    right = min(right, R)
print(max(right - left + 1, 0))
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = sorted(list(map(int, input().split())))
    BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
    ind = 0
    for b, c in BC:
        for i in range(b):
            if A[ind] >= c:
                break
            A[ind] = c
            ind += 1
    print(sum(A))


if __name__ == '__main__':
    main()

Fixed submission:
import heapq
from sys import exit
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
heapq.heapify(A)

ans = sum(A)
for b, c in BC:
    for _ in range(b):
        if len(A) == 0:
            print(ans)
            exit()
        a = heapq.heappop(A)
        if a < c:
            ans += c - a
        else:
            print(ans)
            exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
import heapq
from sys import exit
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
heapq.heapify(A)

ans = sum(A)
for b, c in BC:
    for _ in range(b):
        a = heapq.heappop(A)
        if a < c:
            ans += c - a
        else:
            print(ans)
            exit()
print(ans)


Fixed submission:
import heapq
from sys import exit
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
heapq.heapify(A)

ans = sum(A)
for b, c in BC:
    for _ in range(b):
        if len(A) == 0:
            print(ans)
            exit()
        a = heapq.heappop(A)
        if a < c:
            ans += c - a
        else:
            print(ans)
            exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = []
a = 0
b = 0
both = 0
count = 0
for i in range(N):
    s = input()
    S.append(s)
    if "AB" in s:
        count += 1
    if s[0] == "B":
        b += 1
        if s[-1] == "A":
            both += 1
    if s[-1] == "A":
        a += 1
a -= both
b -= both
if a>0 and b>0:
    count += both+1 + min(a-1, b-1)
elif (a>0 and b==0) or (a==0 and b>0):
    count += both
else:
    count += both -1


print(count)


Fixed submission:
N, K = map(int, input().split())
print(N-K+1)
Buggy python submission (verdict: Runtime Error):
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)


Fixed submission:
n = int(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//i - 1
    if x!=0:
        if n%x == n//x:
            result+=x

print(result)