Swap

AtCoder
IDabc227_e
Time2000ms
Memory256MB
Difficulty
Given is a string $S$ consisting of `K`, `E`, `Y`. How many strings are there that can be obtained with at most $K$ swaps of two adjacent characters in $S$? ## Constraints * $2 \leq |S| \leq 30$ * $0 \leq K \leq 10^9$ * $S$ consists of `K`, `E`, `Y`. ## Input Input is given from Standard Input in the following format: $S$ $K$ [samples]
Samples
Input #1
KEY
1
Output #1
3

With at most one swap, there are three strings that can be obtained: `KEY`, `EKY`, `KYE`.
Input #2
KKEE
2
Output #2
4

With at most two swaps, there are four strings that can be obtained: `KKEE`, `KEKE`, `EKKE`, `KEEK`.
Input #3
KKEEYY
1000000000
Output #3
90
API Response (JSON)
{
  "problem": {
    "name": "Swap",
    "description": {
      "content": "Given is a string $S$ consisting of `K`, `E`, `Y`. How many strings are there that can be obtained with at most $K$ swaps of two adjacent characters in $S$?",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc227_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given is a string $S$ consisting of `K`, `E`, `Y`.\nHow many strings are there that can be obtained with at most $K$ swaps of two adjacent characters in $S$?\n\n## Constraints\n\n*   $2 \\leq |S| \\leq 30$\n*...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments