• + 3 comments

    My python solution

    n = int(input())
    print((n**2)%1000000007)
    

    Explanation

    You need not make it that complicated t(n) = n^2 - (n-1)^2 See the pattern. Every addition in S(n) we are subtracting the previous term For better understanding see the inductive approach.

    S1 = t1 = 1^2 - (n-1)^2 =1
    S2 = t1 + t2 = 1 + 2^2 -(2-1)^2 = 1+4-1 = 4
    S3 = S2 + t3 = 4 + 3^2 - (3-1)^2 = 4 + 9 - 4 = 9
    

    So my answer would be

    Sn = n^2%1000000007