#include <algorithm>
#include <array>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

template<const int &MOD>
struct _m_int {
    int val;

    _m_int(int64_t v = 0) {
        if (v < 0) v = v % MOD + MOD;
        if (v >= MOD) v %= MOD;
        val = int(v);
    }

    static int inv_mod(int a, int m = MOD) {
        // https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example
        int g = m, r = a, x = 0, y = 1;

        while (r != 0) {
            int q = g / r;
            g %= r; swap(g, r);
            x -= q * y; swap(x, y);
        }

        return x < 0 ? x + m : x;
    }

    explicit operator int() const { return val; }
    explicit operator int64_t() const { return val; }

    _m_int& operator+=(const _m_int &other) {
        val -= MOD - other.val;
        if (val < 0) val += MOD;
        return *this;
    }

    _m_int& operator-=(const _m_int &other) {
        val -= other.val;
        if (val < 0) val += MOD;
        return *this;
    }

    static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
#if !defined(_WIN32) || defined(_WIN64)
        return unsigned(x % m);
#endif
        // Optimized mod for Codeforces 32-bit machines.
        // x must be less than 2^32 * m for this to work, so that x / m fits in a 32-bit unsigned int.
        unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
        unsigned quot, rem;
        asm("divl %4\n"
            : "=a" (quot), "=d" (rem)
            : "d" (x_high), "a" (x_low), "r" (m));
        return rem;
    }

    _m_int& operator*=(const _m_int &other) {
        val = fast_mod(uint64_t(val) * other.val);
        return *this;
    }

    _m_int& operator/=(const _m_int &other) {
        return *this *= other.inv();
    }

    friend _m_int operator+(const _m_int &a, const _m_int &b) { return _m_int(a) += b; }
    friend _m_int operator-(const _m_int &a, const _m_int &b) { return _m_int(a) -= b; }
    friend _m_int operator*(const _m_int &a, const _m_int &b) { return _m_int(a) *= b; }
    friend _m_int operator/(const _m_int &a, const _m_int &b) { return _m_int(a) /= b; }

    _m_int& operator++() {
        val = val == MOD - 1 ? 0 : val + 1;
        return *this;
    }

    _m_int& operator--() {
        val = val == 0 ? MOD - 1 : val - 1;
        return *this;
    }

    _m_int operator++(int) { _m_int before = *this; ++*this; return before; }
    _m_int operator--(int) { _m_int before = *this; --*this; return before; }

    _m_int operator-() const {
        return val == 0 ? 0 : MOD - val;
    }

    bool operator==(const _m_int &other) const { return val == other.val; }
    bool operator!=(const _m_int &other) const { return val != other.val; }

    _m_int inv() const {
        return inv_mod(val);
    }

    _m_int pow(int64_t p) const {
        if (p < 0)
            return inv().pow(-p);

        _m_int a = *this, result = 1;

        while (p > 0) {
            if (p & 1)
                result *= a;

            p >>= 1;

            if (p > 0)
                a *= a;
        }

        return result;
    }

    friend ostream& operator<<(ostream &os, const _m_int &m) {
        return os << m.val;
    }
};

extern const int MOD = 998244353;
using mod_int = _m_int<MOD>;


const int MAX = 305;

int N;
vector<int> S;
vector<int> suffix_counts[2];
int latest_suffix[MAX][MAX];
int most_extra[MAX][MAX][MAX][3];

void recurse(int index, array<int, 2> counts, int extra, int carry) {
    if (index >= N && carry == 1 && extra <= 0)
        return;

    if (carry != 1 || extra > 0) {
        array<int, 2> combined = {counts[0] + suffix_counts[0][index], counts[1] + suffix_counts[1][index]};
        latest_suffix[combined[0]][combined[1]] = max(latest_suffix[combined[0]][combined[1]], index);
    }

    if (index >= N)
        return;

    if (extra <= most_extra[index][counts[0]][counts[1]][carry + 1])
        return;

    most_extra[index][counts[0]][counts[1]][carry + 1] = extra;

    if (carry == 0) {
        // 1
        counts[S[index]]++;
        recurse(index + 1, counts, extra, -1);
        counts[S[index]]--;

        // 0
        recurse(index + 1, counts, extra + 1, -1);
    } else if (carry == 1) {
        // 0
        recurse(index + 1, counts, extra, -1);

        if (extra > 0)
            recurse(index, counts, extra - 1, -1);
    } else {
        // 1
        counts[S[index]]++;
        recurse(index + 1, counts, extra, 1);
        counts[S[index]]--;

        // 0
        recurse(index + 1, counts, extra, 0);
    }
}

mod_int dp[MAX][MAX][MAX];

mod_int solve(array<int, 2> counts, int suffix) {
    if (counts[0] + counts[1] > N || suffix < 0)
        return 0;

    mod_int &ans = dp[counts[0]][counts[1]][suffix];

    if (ans.val >= 0)
        return ans;

    ans = 0;

    if (suffix <= latest_suffix[counts[0]][counts[1]])
        ans++;

    int previous = suffix == 0 ? -1 : S[suffix - 1];
    ans += solve({counts[0] + 1, counts[1]}, suffix - (previous == 0));
    ans += solve({counts[0], counts[1] + 1}, suffix - (previous == 1));
    return ans;
}

int main() {
    string str;
    cin >> str;
    N = int(str.size());
    S.resize(N);

    for (int i = 0; i < N; i++)
        S[i] = str[i] - '0';

    for (int x = 0; x < 2; x++) {
        suffix_counts[x].assign(N + 1, 0);

        for (int i = N - 1; i >= 0; i--)
            suffix_counts[x][i] = suffix_counts[x][i + 1] + (S[i] == x);
    }

    memset(latest_suffix, -1, sizeof(latest_suffix));
    memset(most_extra, -1, sizeof(most_extra));
    recurse(0, {0, 0}, 0, -1);

    memset(dp, -1, sizeof(dp));
    cout << solve({0, 0}, N) - 1 << '\n';
}

### Prompt

Develop a solution in cpp to the problem described below:

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.

Examples

Input

0001


Output

8


Input

110001


Output

24


Input

11101111011111000000000110000001111100011111000000001111111110000000111111111


Output

697354558

### Response

```cpp
#include <algorithm>
#include <array>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

template<const int &MOD>
struct _m_int {
    int val;

    _m_int(int64_t v = 0) {
        if (v < 0) v = v % MOD + MOD;
        if (v >= MOD) v %= MOD;
        val = int(v);
    }

    static int inv_mod(int a, int m = MOD) {
        // https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example
        int g = m, r = a, x = 0, y = 1;

        while (r != 0) {
            int q = g / r;
            g %= r; swap(g, r);
            x -= q * y; swap(x, y);
        }

        return x < 0 ? x + m : x;
    }

    explicit operator int() const { return val; }
    explicit operator int64_t() const { return val; }

    _m_int& operator+=(const _m_int &other) {
        val -= MOD - other.val;
        if (val < 0) val += MOD;
        return *this;
    }

    _m_int& operator-=(const _m_int &other) {
        val -= other.val;
        if (val < 0) val += MOD;
        return *this;
    }

    static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
#if !defined(_WIN32) || defined(_WIN64)
        return unsigned(x % m);
#endif
        // Optimized mod for Codeforces 32-bit machines.
        // x must be less than 2^32 * m for this to work, so that x / m fits in a 32-bit unsigned int.
        unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
        unsigned quot, rem;
        asm("divl %4\n"
            : "=a" (quot), "=d" (rem)
            : "d" (x_high), "a" (x_low), "r" (m));
        return rem;
    }

    _m_int& operator*=(const _m_int &other) {
        val = fast_mod(uint64_t(val) * other.val);
        return *this;
    }

    _m_int& operator/=(const _m_int &other) {
        return *this *= other.inv();
    }

    friend _m_int operator+(const _m_int &a, const _m_int &b) { return _m_int(a) += b; }
    friend _m_int operator-(const _m_int &a, const _m_int &b) { return _m_int(a) -= b; }
    friend _m_int operator*(const _m_int &a, const _m_int &b) { return _m_int(a) *= b; }
    friend _m_int operator/(const _m_int &a, const _m_int &b) { return _m_int(a) /= b; }

    _m_int& operator++() {
        val = val == MOD - 1 ? 0 : val + 1;
        return *this;
    }

    _m_int& operator--() {
        val = val == 0 ? MOD - 1 : val - 1;
        return *this;
    }

    _m_int operator++(int) { _m_int before = *this; ++*this; return before; }
    _m_int operator--(int) { _m_int before = *this; --*this; return before; }

    _m_int operator-() const {
        return val == 0 ? 0 : MOD - val;
    }

    bool operator==(const _m_int &other) const { return val == other.val; }
    bool operator!=(const _m_int &other) const { return val != other.val; }

    _m_int inv() const {
        return inv_mod(val);
    }

    _m_int pow(int64_t p) const {
        if (p < 0)
            return inv().pow(-p);

        _m_int a = *this, result = 1;

        while (p > 0) {
            if (p & 1)
                result *= a;

            p >>= 1;

            if (p > 0)
                a *= a;
        }

        return result;
    }

    friend ostream& operator<<(ostream &os, const _m_int &m) {
        return os << m.val;
    }
};

extern const int MOD = 998244353;
using mod_int = _m_int<MOD>;


const int MAX = 305;

int N;
vector<int> S;
vector<int> suffix_counts[2];
int latest_suffix[MAX][MAX];
int most_extra[MAX][MAX][MAX][3];

void recurse(int index, array<int, 2> counts, int extra, int carry) {
    if (index >= N && carry == 1 && extra <= 0)
        return;

    if (carry != 1 || extra > 0) {
        array<int, 2> combined = {counts[0] + suffix_counts[0][index], counts[1] + suffix_counts[1][index]};
        latest_suffix[combined[0]][combined[1]] = max(latest_suffix[combined[0]][combined[1]], index);
    }

    if (index >= N)
        return;

    if (extra <= most_extra[index][counts[0]][counts[1]][carry + 1])
        return;

    most_extra[index][counts[0]][counts[1]][carry + 1] = extra;

    if (carry == 0) {
        // 1
        counts[S[index]]++;
        recurse(index + 1, counts, extra, -1);
        counts[S[index]]--;

        // 0
        recurse(index + 1, counts, extra + 1, -1);
    } else if (carry == 1) {
        // 0
        recurse(index + 1, counts, extra, -1);

        if (extra > 0)
            recurse(index, counts, extra - 1, -1);
    } else {
        // 1
        counts[S[index]]++;
        recurse(index + 1, counts, extra, 1);
        counts[S[index]]--;

        // 0
        recurse(index + 1, counts, extra, 0);
    }
}

mod_int dp[MAX][MAX][MAX];

mod_int solve(array<int, 2> counts, int suffix) {
    if (counts[0] + counts[1] > N || suffix < 0)
        return 0;

    mod_int &ans = dp[counts[0]][counts[1]][suffix];

    if (ans.val >= 0)
        return ans;

    ans = 0;

    if (suffix <= latest_suffix[counts[0]][counts[1]])
        ans++;

    int previous = suffix == 0 ? -1 : S[suffix - 1];
    ans += solve({counts[0] + 1, counts[1]}, suffix - (previous == 0));
    ans += solve({counts[0], counts[1] + 1}, suffix - (previous == 1));
    return ans;
}

int main() {
    string str;
    cin >> str;
    N = int(str.size());
    S.resize(N);

    for (int i = 0; i < N; i++)
        S[i] = str[i] - '0';

    for (int x = 0; x < 2; x++) {
        suffix_counts[x].assign(N + 1, 0);

        for (int i = N - 1; i >= 0; i--)
            suffix_counts[x][i] = suffix_counts[x][i + 1] + (S[i] == x);
    }

    memset(latest_suffix, -1, sizeof(latest_suffix));
    memset(most_extra, -1, sizeof(most_extra));
    recurse(0, {0, 0}, 0, -1);

    memset(dp, -1, sizeof(dp));
    cout << solve({0, 0}, N) - 1 << '\n';
}

```