#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include #include using namespace __gnu_pbds; using namespace std; #define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define endl '\n' typedef long long ll; // #define mod1 (ll)1000000007 #define mod2 (ll)998244353 #define pll pair typedef long double lb; typedef tree< pair, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define eps (lb)(1e-9) struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; // Operator overloads template // cin >> pair istream& operator>>(istream &istream, pair &p) { return (istream >> p.first >> p.second); } template // cin >> vector istream& operator>>(istream &istream, vector &v) { for (auto &it : v) cin >> it; return istream; } template // cout << pair ostream& operator<<(ostream &ostream, const pair &p) { return (ostream << p.first << " " << p.second); } template // cout << vector ostream& operator<<(ostream &ostream, const vector &c) { for (auto &it : c) cout << it << " "; return ostream; } // Utility functions template void print(T &&t) { cout << t << "\n"; } template void print(T &&t, Args &&... args) { cout << t << " "; print(forward(args)...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll random(ll p){ // gives random number in [0,p] return uniform_int_distribution(0, p)(rng); } ll n; vectorv; ll mod=mod2; ll mod1=mod2; ll dp[4000][4000]; ll sum[4000][4000]; ll pwr[5000]; ll power(ll a, ll b, ll c=mod1){ if(a==0){ return 0;} else if(b==0||a==1){ return 1;} ll p=power(a,b/2,c); p*=p; p%=c; if(b%2){p*=a;} p%=c; return p;} ll modinv(ll a, ll c=mod1){ return power(a,c-2,c); } const ll MAXN =1000000; ll fac[MAXN+1]; ll invfac[MAXN+1]; void factorial(ll mod=mod1){ fac[0]=1; for(ll i(1);i<=MAXN;++i){fac[i]=i*fac[i-1]; fac[i]%=mod;} invfac[MAXN]=modinv(fac[MAXN],mod); for(ll i(MAXN-1);i>-1;--i) { invfac[i]=(i+1ll)*invfac[i+1]; invfac[i]%=mod; } for(ll i(0);i<5000;++i){ pwr[i]=power(2,i); } } ll C(ll n,ll r,ll mod=mod1){ if(n<0||r<0||r>n){return 0;} ll p=fac[n]; ll q=invfac[n-r]*invfac[r]; q%=mod; p*=q; p%=mod; return p; } void pre(){ for(ll j(0);ji){ dp[i][j]=0; } else if(j==i){ dp[i][j]=(v[0]==1); } else if(v[i-j]==0){ dp[i][j]=sum[i-1][j]; } else{ dp[i][j]=pwr[i-j]; if(j>0){ dp[i][j]+=(sum[i-1][j]-sum[i-j-1][j]); } } rs+=dp[i][j]; rs%=mod; sum[i][j]=rs; } } } void solve(); int main() { io; ll t=1,n=1; // cin>>t; factorial(); while (t--){ solve(); } return 0; } void solve(){ cin>>n; v.resize(n); for(ll i(0);i>p; v[i]=p-'0'; } pre(); ll ans=0; for(ll i(0);i