
    In an adaptive learning system, calculate the total cumulative difficulty threshold a student must overcome by summing the first n difficulty levels, where each level's threshold follows the Perrin sequence pattern (each new threshold is determined by adding the values from three levels prior). Given a progression stage n, determine the sum of all difficulty thresholds up to that stage.
    

    
def cal_sum(n):
    """
    In an adaptive learning system, calculate the total cumulative difficulty threshold a student must overcome by summing the first n difficulty levels, where each level's threshold follows the Perrin sequence pattern (each new threshold is determined by adding the values from three levels prior). Given a progression stage n, determine the sum of all difficulty thresholds up to that stage.
    

    """
def cal_sum(n):
    """
    In an adaptive learning system, calculate the total cumulative difficulty threshold a student must overcome by summing the first n difficulty levels, where each level's threshold follows the Perrin sequence pattern (each new threshold is determined by adding the values from three levels prior). Given a progression stage n, determine the sum of all difficulty thresholds up to that stage.
    

    """
    a = 3
    b = 0
    c = 2
    if n == 0:
        return 3
    if n == 1:
        return 3
    if n == 2:
        return 5
    sum = 5
    while n > 2:
        d = a + b
        sum = sum + d
        a = b
        b = c
        c = d
        n = n - 1
    return sum