public int maximalLength(String s) {
        int maximalLength = 0;
        for (int i = 0; i < s.length(); i++) {
            String substring1 = s.substring(0, i);
            String substring2 = s.substring(i);
            maximalLength = Math.max(maximalLength, calculateLengthLongestSubsequence(substring1, substring2) * 2);
        }
        return maximalLength;
    }