Half Palindromes

AtCoder
ID1202Contest_e
Time3000ms
Memory256MB
Difficulty
You are given a string $S$ consisting of lowercase letters. For each contiguous substring of $S$ (there are $|S|(|S|+1)/2$ such substrings), solve the following problem, and compute the sum of the answers. Problem: You are given a string $T$ consisting of lowercase letters. Compute the minimum possible length of a string that can be obtained from $T$ by repeatedly applying the following operation an arbitrary number of times. * Take a prefix of $T$ that is a palindrome of odd length. Let the length be $2k+1$. Remove the first $k$ letters of $T$. ## Constraints * $1\leq |S|\leq 10^6$ * $S$ consists of lowercase letters. ## Input The input is given from Standard Input in the following format: $S$ [samples]
Samples
Input #1
abab
Output #1
16

If $T$ is `a` or `b`, the answer is $1$.
If $T$ is `ab` or `ba`, the answer is $2$.
If $T$ is `aba` or `bab`, applying the operation with $k=1$ once is optimal, and the answer is $2$.
If $T$ is `abab`, applying the operation with $k=1$ twice is optimal, and the answer is $2$.
Therefore, the whole answer is $1\times 4 + 2\times 3 + 2\times 2 + 2\times 1 = 16$.
Input #2
abacaba
Output #2
67
Input #3
tabatadebatabata
Output #3
739
API Response (JSON)
{
  "problem": {
    "name": "Half Palindromes",
    "description": {
      "content": "You are given a string $S$ consisting of lowercase letters. For each contiguous substring of $S$ (there are $|S|(|S|+1)/2$ such substrings), solve the following problem, and compute the sum of the ans",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "1202Contest_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a string $S$ consisting of lowercase letters. For each contiguous substring of $S$ (there are $|S|(|S|+1)/2$ such substrings), solve the following problem, and compute the sum of the ans...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments