(∀x∀)

AtCoder
IDabc242_e
Time2000ms
Memory256MB
Difficulty
Solve the following problem for $T$ test cases. Given an integer $N$ and a string $S$, find the number of strings $X$ that satisfy all of the conditions below, modulo $998244353$. * $X$ is a string of length $N$ consisting of uppercase English letters. * $X$ is a palindrome. * $X \le S$ in lexicographical order. * That is, $X=S$ or $X$ is lexicographically smaller than $S$. ## Constraints * $1 \le T \le 250000$ * $N$ is an integer between $1$ and $10^6$ (inclusive). * In a single input, the sum of $N$ over the test cases is at most $10^6$. * $S$ is a string of length $N$ consisting of uppercase English letters. ## Input Input is given from Standard Input in the following format: $T$ $\mathrm{case}_1$ $\mathrm{case}_2$ $\vdots$ $\mathrm{case}_T$ Here, $\mathrm{case}_i$ represents the $i$\-th test case. Each test case is in the following format: $N$ $S$ [samples]
Samples
Input #1
5
3
AXA
6
ABCZAZ
30
QWERTYUIOPASDFGHJKLZXCVBNMQWER
28
JVIISNEOXHSNEAAENSHXOENSIIVJ
31
KVOHEEMSOZZASHENDIGOJRTJVMVSDWW
Output #1
24
29
212370247
36523399
231364016

This input contains five test cases.
Test case #1:  
The $24$ strings satisfying the conditions are `AAA`$,$ `ABA`$,$ `ACA`$,...,$ `AXA`.
Test case #2:  
$S$ may not be a palindrome.
Test case #3:  
Be sure to find the count modulo $998244353$.
API Response (JSON)
{
  "problem": {
    "name": "(∀x∀)",
    "description": {
      "content": "Solve the following problem for $T$ test cases. Given an integer $N$ and a string $S$, find the number of strings $X$ that satisfy all of the conditions below, modulo $998244353$. *   $X$ is a string",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc242_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Solve the following problem for $T$ test cases.\nGiven an integer $N$ and a string $S$, find the number of strings $X$ that satisfy all of the conditions below, modulo $998244353$.\n\n*   $X$ is a string...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments