human
Write me a code to count all possible unique sum of series K , K + 1 , K + 2 , K + 3 , K + 4 , given the following:
Count all possible unique sum of series K , K + 1 , K + 2 , K + 3 , K + 4 , ... , K + N | Function to count the unique sum.
Set fsum [ 0 ] as ar [ 0 ].
Set rsum [ 0 ] as ar [ n ].
For each i update fsum [ i ] with ar [ i ] + fsum [ i - 1 ].
For each i from n - 1 , update rsum [ i ] with ar [ i ] + fsum [ i + 1 ].
K represent size of subset as explained above.
Using above relation.
Return the result.
Given a number N.
Function call"
How can the above be solved in Python?
assistant
#Here is code to count all possible unique sum of series K , K + 1 , K + 2 , K + 3 , K + 4 , .
 def count_unique_sum ( n ) :
	ar = [ 0 ] * ( n + 1 )
	fsum = [ 0 ] * ( n + 1 )
	rsum = [ 0 ] * ( n + 1 )
	ans = 1
	for i in range ( 0 , n + 1 ) :
		ar [ i ] = i
	fsum [ 0 ] = ar [ 0 ]
	rsum [ n ] = ar [ n ]
	for i in range ( 1 , n + 1 ) :
		fsum [ i ] = ar [ i ] + fsum [ i - 1 ]
	for i in range ( n - 1 , - 1 , - 1 ) :
		rsum [ i ] = ar [ i ] + rsum [ i + 1 ]
	for k in range ( 2 , n + 1 ) :
		ans += ( 1 + rsum [ n + 1 - k ] - fsum [ k - 1 ] )
	return ans
N = 4
print ( count_unique_sum ( N ) )