Problem:
Score : 1100 points

Problem Statement

Given is a string S consisting of 0 and 1. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times:

Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only when S has two or more characters.

Constraints

1 \leq |S| \leq 300

S consists of 0 and 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of strings, modulo 998244353, that can result from applying the operation on S zero or more times.

Sample Input 1

0001

Sample Output 1

8

Eight strings, 0001, 001, 010, 00, 01, 10, 0, and 1, can result.

Sample Input 2

110001

Sample Output 2

24

Sample Input 3

11101111011111000000000110000001111100011111000000001111111110000000111111111

Sample Output 3

697354558

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;
    int mod = 998244353;

    void calc()
    {
        string S = cin.next();
        
        /*
        string S = "";
        for (int i = 0; i < 150; i++)
        {
            S += "01";
        }
        */
        
        int[] ar = new int[S.Length];
        for (int i = 0; i < S.Length; i++)
        {
            ar[i] = (int)(S[i] - '0');
        }
        int[] revar = (int[])ar.Clone();
        Array.Reverse(revar);

        int ans = 0;

        bool[,,] check = new bool[S.Length + 2, S.Length + 2, S.Length + 2];
        check[0, 0, 0] = true;
        for (int i = 0; i < S.Length; i++)
        {
            for (int j = 0; j <= S.Length; j++)
            {
                for (int k = 0; k <= S.Length; k++)
                {
                    if (!check[i, j, k]) continue;
                    int num = i + j + k;
                    if(num + 2 <= S.Length)
                    {
                        if (ar[num] == 0 || ar[num + 1] == 0) check[i + 1, j + 1, k] = true;
                        if (ar[num] == 1 || ar[num + 1] == 1) check[i + 1, j, k + 1] = true;
                    }
                    if(num + 1 <= S.Length)
                    {
                        if (j != 0 && ar[num] == 1) check[i + 1, j - 1, k + 1] = true;
                        if (k != 0 && ar[num] == 0) check[i + 1, j + 1, k - 1] = true;
                        check[i + 1, j, k] = true;
                    }
                    if (j >= 1) check[i + 1, j - 1, k] = true;
                    if (k >= 1) check[i + 1, j, k - 1] = true;
                }
            }
        }

        int[,,] dp = new int[S.Length + 1, S.Length + 2, S.Length + 2];
        dp[0, 0, 0] = 1;

        for (int a = 0; a <= S.Length; a++)
        {
            for (int b = 0; b <= S.Length - a; b++)
            {
                for (int c = 0; c <= S.Length - a - b; c++)
                {
                    if (dp[a, b, c] == 0) continue;

                    for (int k = 0; k < 2; k++)
                    {
                        if (a != S.Length && revar[a] == k)
                        {
                            dp[a + 1, b, c] += dp[a, b, c];
                            if (dp[a + 1, b, c] >= mod) dp[a + 1, b, c] -= mod;
                        }
                        else
                        {
                            if (k == 0)
                            {
                                dp[a, b + 1, c] += dp[a, b, c];
                                if (dp[a, b + 1, c] >= mod) dp[a, b + 1, c] -= mod;
                            }
                            if (k == 1)
                            {
                                dp[a, b, c + 1] += dp[a, b, c];
                                if (dp[a, b, c + 1] >= mod) dp[a, b, c + 1] -= mod;
                            }
                        }
                    }
                }
            }
        }


        for (int a = 0; a <= S.Length; a++)
        {
            for (int b = 0; b <= S.Length - a; b++)
            {
                for (int c = 0; c <= S.Length - a - b; c++)
                {
                    if (check[S.Length - a - b - c, b, c] && dp[a,b,c] >= 1)
                    {
                        ans += dp[a, b, c];
                        if (ans >= mod) ans -= mod;
                    }
                }
                //if (dp[a, b, c] >= 0) Console.WriteLine(a + " " + b + " " + c + " " + dp[a, b, c]);
            }
        }
        ans += mod - 1;
        ans %= mod;
        Console.WriteLine(ans);

    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}