Insights

  1. if a string is k-palindrome, then it is also a k-1 palindrome!!!
    Proof: simple induction on k
    
  2. if a string is k-palindrome <=> then it is a palindrome, plus it is left half is a k - 1 palindrome
    Proof: induction on k, base case k = 2
    
So we need to calculate maxK(l, r) = max degress of k in in the substring [l, r]. This means we need 2 DPs, one for if the substring is a palindrome, another for the max degree of left half >= k - 1.In the end, we do a reverse prefix sum from s to 1