Problem p02624 (python)

Fixed submission:
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import copy
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)


def main():
    N = I()
    c = [1] * (N + 1)
    
    for i in range(2, N + 1):
        k = i
        while k <= N:
            c[k] += 1
            k += i

    ans = sum(i * c for (i, c) in enumerate(c))
    print(ans)
main()

Buggy submission (verdict: Runtime Error):
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    N, M, K = LI()
    A = LI()
    B = LI()

    i, j, ans, cum = 0, 0, 0, 0

    while True:
        if (i < N) and (j < M):
            if (cum + A[i] <= K) and (cum + B[j] <= K):
                if A[i] <= B[j]:
                    cum += A[i]
                    i += 1
                else:
                    cum += B[j]
                    j += 1
            elif cum + A[i] <= K:
                cum += A[i]
                i += 1
            elif cum + B[j] <= K:
                cum += B[j]
                j += 1
            else:
                break
            ans += 1
        elif i < N:
            if cum + A[i] <= K:
                cum += A[i]
                i += 1
                ans += 1
            else:
                break
        elif j < M:
            if cum + B[j] <= K:
                cum += B[j]
                j += 1
                ans += 1
            else:
                break
        else:
            break

    print(ans)

main()

Buggy submission (verdict: Runtime Error):
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import copy
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def main():
    N = I()
    era = get_sieve_of_eratosthenes(N+1)
    ans = 0
    divsdic = [None] * (N + 1)

    def get_divisor_count(k):
        n = k
        d = defaultdict(int)
        while k != 0:
            if divsdic[k] is not None:
                for (k, v) in divsdic[k].items():
                    d[k] += v
                divsdic[n] = copy.copy(d)
                return copy.copy(d)
            for i in era:
                if k % i == 0:
                    k //= i
                    d[i] += 1
                    break
            else:
                break
        divsdic[n] = copy.copy(d)
        return d

    for i in range(1, N + 1):
        d = get_divisor_count(i)
        tmp = 1
        for v in d.values():
            tmp *= v + 1
        ans += tmp * i

    print(ans)


main()