No Permutations

AtCoder
IDagc064_f
Time8000ms
Memory256MB
Difficulty
You are given a positive integer $N$. Print the number, modulo $998244353$, of sequences $A$ of length $3N$ that contain each integer from $1$ through $N$ three times and satisfy the following condition. * $A$ has no contiguous subsequence of length $N$ that is a permutation of the sequence $(1, 2, \ldots, N)$. ## Constraints * $1 \leq N \leq 2 \times 10^5$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ [samples]
Samples
Input #1
3
Output #1
132

For instance, $A = (1, 3, 3, 2, 2, 2, 1, 1, 3)$ satisfies the condition in the problem statement. On the other hand, $A = (1, 3, 3, 2, 2, 3, 1, 1, 2)$ does not, because the $5$\-th, $6$\-th, $7$\-th elements of $A$ form a contiguous subsequence that is a permutation of the sequence $(1, 2, 3)$.
Input #2
123456
Output #2
31984851
API Response (JSON)
{
  "problem": {
    "name": "No Permutations",
    "description": {
      "content": "You are given a positive integer $N$. Print the number, modulo $998244353$, of sequences $A$ of length $3N$ that contain each integer from $1$ through $N$ three times and satisfy the following conditi",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 8000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc064_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a positive integer $N$. Print the number, modulo $998244353$, of sequences $A$ of length $3N$ that contain each integer from $1$ through $N$ three times and satisfy the following conditi...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments