human
Difference Array | Range update query in O ( 1 ) | Creates a diff array D [ ] for A [ ] and returns it after filling initial values ..
We use one extra space because update ( l , r , x ) updates D [ r + 1 ].
Does range update.
Prints updated Array.
Note that A [ 0 ] or D [ 0 ] decides values of rest of the elements ..
Array to be updated.
Create and fill difference Array.
After below update ( l , r , x ) , the elements should become 20 , 15 , 20 , 40.
After below updates , the array should become 30 , 35 , 70 , 60"
How can the above be solved in Python?

=====
Write me a code to difference Array and the other steps required?
assistant
#Here is code to difference Array and the other steps required.
 def initializeDiffArray ( A ) :
	n = len ( A )
	D = [ 0 for i in range ( 0 , n + 1 ) ]
	D [ 0 ] = A [ 0 ] ; D [ n ] = 0
	for i in range ( 1 , n ) :
		D [ i ] = A [ i ] - A [ i - 1 ]
	return D
def update ( D , l , r , x ) :
	D [ l ] += x
	D [ r + 1 ] -= x
def printArray ( A , D ) :
	for i in range ( 0 , len ( A ) ) :
		if ( i == 0 ) :
			A [ i ] = D [ i ]
		else :
			A [ i ] = D [ i ] + A [ i - 1 ]
		print ( A [ i ] , end = " ▁ " )
	print ( " " )
A = [ 10 , 5 , 20 , 40 ]
D = initializeDiffArray ( A )
update ( D , 0 , 1 , 10 )
printArray ( A , D )
update ( D , 1 , 3 , 20 )
update ( D , 2 , 2 , 30 )
printArray ( A , D )