human
Count all sub | Function to find the count of all the substrings with weight of characters atmost K.
Hashmap to store all substrings.
Iterate over all substrings.
Maintain the sum of all characters encountered so far.
Maintain the substring till the current position.
Get the position of the character in string Q.
Add weight to current sum.
Add current character to substring.
If sum of characters is <= K then insert in into the set.
Finding the size of the set.
Driver code"
Solution in Python:

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