Problem:
Score : 1400 points

Problem Statement

Consider the following set of rules for encoding strings consisting of 0 and 1:

Strings 0 and 1 can be encoded as 0 and 1, respectively.

If strings A and B can be encoded as P and Q, respectively, then string AB can be encoded as PQ.

If string A can be encoded as P and K \geq 2 is a positive integer, then string AA...A (A repeated K times) can be encoded as (PxK).

For example, string 001001001, among other possibilities, can be encoded as 001001001, 00(1(0x2)x2)1 and (001x3).

Let's call string A a subset of string B if:

A and B are equal in length and consist of 0 and 1;

for all indices i such that A_i = 1, it's also true that B_i = 1.

You are given string S consisting of 0 and 1. Find the total number of distinct encodings of all subsets of S, modulo 998244353.

Constraints

1 \leq |S| \leq 100

S consists of 0 and 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the total number of distinct encodings of all subsets of S modulo 998244353.

Sample Input 1

011

Sample Output 1

9

There are four subsets of S:

011 can be encoded as 011 and 0(1x2);

010 can be encoded as 010;

001 can be encoded as 001 and (0x2)1;

000 can be encoded as 000, 0(0x2), (0x2)0 and (0x3).

Thus, the total number of encodings of all subsets of S is 2 + 1 + 2 + 4 = 9.

Sample Input 2

0000

Sample Output 2

10

This time S has only one subset, but it can be encoded in 10 different ways.

Sample Input 3

101110

Sample Output 3

156

Sample Input 4

001110111010110001100000100111

Sample Output 4

363383189

Don't forget to take the result modulo 998244353.

Solution in Rust (1.42.0) (judge verdict: Accepted)

use std::io::Read;
use std::collections::HashMap;

const MOD: u64 = 998244353;

fn solve(s: u128, n: usize, mem: &mut HashMap<(u128, usize), u64>) -> u64 {
    if n == 0 { return 1 }
    if n == 1 { return (s%2 + 1) as u64 }
    if let Some(&r) = mem.get(&(s, n)) { return r }
    let mut res = (s%2 + 1) as u64 * solve(s/2, n-1, mem) % MOD;
    for l in 1..n {
        if 2*l > n { break }
        let mut ns = s & (s >> l);
        for r in 2..=n/l {
            if l*r > n { break; }
            res = (res + solve(ns, l, mem) * solve(s >> r*l, n-r*l, mem)) % MOD;
            ns &= s >> r*l;
        }
    }
    mem.insert((s, n), res);
    res
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let s = buf.trim().as_bytes();
    let n = s.len();
    let mut v : u128 = 0;
    for i in 0..n {
        if s[i] == b'1' { v |= 1 << i }
    }
    let mut mem = HashMap::new();
    let res = solve(v, n, &mut mem);
    println!("{}", res);
}