CF BUDDY
← Problems·

1147D · Palindrome XOR

2400 · dfs and similar, graphs

Problem: You are given a string ss consisting of characters "1", "0", and "?". The first character of ss is guaranteed to be "1". Let mm be the number of characters in ss.

Count the number of ways we can choose a pair of integers a,ba, b that satisfies the following:

  • 1a<b<2m1 \leq a < b < 2^m
  • When written without leading zeros, the base-2 representations of aa and bb are both palindromes.
  • The base-2 representation of bitwise XOR of aa and bb matches the pattern ss. We say that tt matches ss if the lengths of tt and ss are the same and for every ii, the ii-th character of tt is equal to the ii-th character of ss, or the ii-th character of ss is "?".

Compute this count modulo 998244353998244353.

Input Format: The first line contains a single string ss (1s10001 \leq |s| \leq 1\,000). ss consists only of characters "1", "0" and "?". It is guaranteed that the first character of ss is a "1".

Output Format: Print a single integer, the count of pairs that satisfy the conditions modulo 998244353998244353.

Note: For the first example, the pairs in base-2 are (111,10001),(11,10101),(1001,11111)(111, 10001), (11, 10101), (1001, 11111).

Sample Cases

Case 1

Input

10110

Output

3

Case 2

Input

1?0???10

Output

44

Case 3

Input

1?????????????????????????????????????

Output

519569202

Case 4

Input

1

Output

0

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback