Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

Life is always full of uncertainties. For example, you might think from the problem title that this is a string problem, but actually it is not.

You are given a string $s$ and a character $c$. Each time, you randomly choose a position $i$ that has not been chosen before, and change $s_i$ to $c$ (if $s_i = c$, it still counts as one operation). You repeat this operation until $s$ becomes a palindrome, and then stop. You want to know the expected number of operations needed.

In particular, if $s$ is already a palindrome at the beginning, the answer is $0$.

Input

The first line contains a string $s$ ($1 \le |s| \le 250000$), guaranteed to consist only of lowercase English letters.

The second line contains a lowercase English letter $c$.

Output

Output one integer on a single line, representing the expected value modulo $998244353$.

Examples

Input 1

abcab
a

Output 1

4

Input 2

abcdcbd
a

Output 2

177465668

Input 3

aba
z

Output 3

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.