Yet Another RGB Sequence

AtCoder
IDabc266_g
Time2000ms
Memory256MB
Difficulty
You are given integers $R$, $G$, $B$, and $K$. How many strings $S$ consisting of `R`, `G`, and `B` satisfy all of the conditions below? Find the count modulo $998244353$. * The number of occurrences of `R`, `G`, and `B` in $S$ are $R$, $G$, and $B$, respectively. * The number of occurrences of `RG` as (contiguous) substrings in $S$ is $K$. ## Constraints * $1 \leq R,G,B\leq 10^6$ * $0 \leq K \leq \mathrm{min}(R,G)$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $R$ $G$ $B$ $K$ [samples]
Samples
Input #1
2 1 1 1
Output #1
6

The following six strings satisfy the conditions.

*   `RRGB`
*   `RGRB`
*   `RGBR`
*   `RBRG`
*   `BRRG`
*   `BRGR`
Input #2
1000000 1000000 1000000 1000000
Output #2
80957240

Find the count modulo $998244353$.
API Response (JSON)
{
  "problem": {
    "name": "Yet Another RGB Sequence",
    "description": {
      "content": "You are given integers $R$, $G$, $B$, and $K$. How many strings $S$ consisting of `R`, `G`, and `B` satisfy all of the conditions below? Find the count modulo $998244353$. *   The number of occurrenc",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc266_g"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given integers $R$, $G$, $B$, and $K$. How many strings $S$ consisting of `R`, `G`, and `B` satisfy all of the conditions below? Find the count modulo $998244353$.\n\n*   The number of occurrenc...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments