def prefix_sums(A):
    """
    This function calculate of sums of eements in given slice (contiguous segments of array).
    Its main idea uses prefix sums which
    are defined as the consecutive totals of the first 0, 1, 2, . . . , n elements of an array.
    
    Args: 
    A: an array represents number of mushrooms growing on the
    consecutive spots along a road.
    
    Returns:
    an array contains the consecutive sums of the first n elements of an array A
    
    To use:
    >> A=[2,3,7,5,1,3,9]
    >> print(prefix_sums(A))
    [0, 2, 5, 12, 17, 18, 21, 30]
    
    Time Complexity: O(n)
    """
    n = len(A)
    P = [0] * (n + 1)
    for k in range(1, n + 1):
        P[k] = P[k - 1] + A[k - 1]
    return P