Explanation with MathJax
Let’s maintain a function $$$f(n, m)$$$ to decide if a pair is good or not.
Case 1: Odd values of $$$n$$$
For odd values of $$$n$$$, we can re-express the string $$$s$$$ as:
$$$ s_1 s_2 \dots s_{\lfloor \frac{n}{2} \rfloor} | s_{\lceil \frac{n}{2} \rceil} | s_{\lceil \frac{n}{2} \rceil + 1} \dots s_n $$$The sum:
$$$ s_1 + s_2 + \dots + s_{\lfloor \frac{n}{2} \rfloor} = f $$$and the middle digit can be denoted as $$$h$$$.
Thus, the total sum is:
$$$ 2f + h. $$$Since $$$h$$$ can be any digit, the sum $$$2f + h$$$ lies between the minimum and maximum possible values, inclusive.
Conditions for a "good" pair: [ \begin{cases} n \leq m \leq 9n, \ n \mod 2 = 1, \end{cases} ] then the pair is YES.
Case 2: Even values of $$$n$$$
For even values of $$$n$$$, we re-express the string $$$s$$$ as:
$$$ s_1 s_2 \dots s_{\lfloor \frac{n}{2} \rfloor} | s_{\lceil \frac{n}{2} \rceil} s_{\lceil \frac{n}{2} \rceil + 1} \dots s_n $$$Using symmetry:
$$$ s_{\lfloor \frac{n}{2} \rfloor} = s_{\lceil \frac{n}{2} \rceil + 1} = h. $$$Let $$$f$$$ denote the left and right segments. The sum of medians is $$$2h$$$, and the total becomes:
$$$ m = 2f + 2h = 2(f + h). $$$For even $$$n$$$, the sum must also satisfy the condition of being even.
Conditions for a "good" pair: [ \begin{cases} n \leq m \leq 9n, \ (n + m) \mod 2 = 0, \end{cases} ] then the pair is YES.
Complexity
For the easy version, we can iterate through all pairs $$$(a, b)$$$, and the complexity will be: [ \mathcal{O}(n^2). ]