human
Count of all sub | Function to count all substrings.
Hashmap to store substrings.
iterate over all substrings.
variable to maintain sum of all characters encountered.
variable to maintain substring till current position.
get position of character in string W.
add weight to current sum.
add current character to substring.
check if sum of characters is <= K insert in Hashmap.
Driver code.
initialise string.
initialise weight"
How can the above be solved in Python?

=====
Give me a code to count of all sub and the other steps required?
assistant
#Here is code to count of all sub and the other steps required.
 def distinctSubstring ( P , Q , K , N ) :
	S = set ( )
	for i in range ( N ) :
		sum = 0
		s = " "
		for j in range ( i , N ) :
			pos = ord ( P [ j ] ) - 97
			sum += ord ( Q [ pos ] ) - 48
			s += P [ j ]
			if ( sum <= K ) :
				S . add ( s )
			else :
				break
	return len ( S )
if __name__ == ' _ _ main _ _ ' :
	S = " abcde "
	W = "12345678912345678912345678"
	K = 5
	N = len ( S )
	print ( distinctSubstring ( S , W , K , N ) )