harbor run -t openthoughts/tasktrove-exp-rpt-taco-v2-taco-9522harbor download openthoughts/tasktrove-exp-rpt-taco-v2-taco-9522A Little Elephant from the Zoo of Lviv loves lucky strings, which are defined as strings composed only of the digits 4 and 7.
The Little Elephant considers a string ( T ) of length ( M ) to be balanced if there exists at least one integer ( X ) (where ( 1 \leq X \leq M )) such that the number of digits 4 in the substring ( T[1, X - 1] ) is equal to the number of digits 7 in the substring ( T[X, M] ).
Example:
The Little Elephant has a string ( S ) of length ( N ) and wants to determine the number of pairs of integers ( (L, R) ) such that ( 1 \leq L \leq R \leq N ) and the substring ( S[L, R] ) is balanced. Your task is to help him find this number.
4
47
74
477
4747477
2
2
3
23
The solution to the problem should be implemented in the file located at /app/.
Important: place your implementation at /app/solution.py so the verifier can run it.