use std::collections::BTreeMap;

const MOD: usize = 998244353;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner(s.lock());
    let n: usize = sc.read();
    let mut s = sc
        .chars()
        .into_iter()
        .map(|c| c as usize - '0' as usize)
        .collect::<Vec<_>>();
    for i in 0..n {
        let c = s[i];
        s.push(c ^ 1);
    }

    let mut ks = vec![];
    for k in 1..(2 * n + 1) {
        if (2 * n) % k == 0 && n % k != 0 && k % 2 == 0 {
            ks.push(k);
        }
    }

    let mut ans = BTreeMap::new();
    for count in ks.into_iter() {
        let t = count / 2;
        let mut dp = vec![1, 0];
        for i in 0..t {
            let mut next = vec![0, 0];
            for under in 0..2 {
                for x in 0..2 {
                    if under == 1 {
                        next[under] += dp[under];
                        next[under] %= MOD;
                    } else if s[i] > x {
                        next[1] += dp[0];
                        next[1] %= MOD;
                    } else if s[i] == x {
                        next[0] += dp[0];
                        next[0] %= MOD;
                    }
                }
            }
            dp = next;
        }

        let mut ok = true;
        for i in 0..n {
            if i % count == i % t {
                if s[i] < s[i % t] {
                    ok = false;
                    break;
                } else if s[i] > s[i % t] {
                    break;
                }
            } else {
                if s[i] < s[i % t] ^ 1 {
                    ok = false;
                    break;
                } else if s[i] > s[i % t] ^ 1 {
                    break;
                }
            }
        }
        //        eprintln!("ok={} dp={:?}", ok, dp);
        let c = if ok { (dp[0] + dp[1]) } else { dp[1] };
        ans.insert(count, c);
    }

    //    eprintln!("{:?}", ans);

    let mut sum = 0;
    let keys = ans.keys().cloned().collect::<Vec<_>>();
    for key in keys.into_iter() {
        let c = *ans.get(&key).unwrap();
        sum += c * key;
        sum %= MOD;
        let mut cur = key * 2;
        while cur <= 2 * n {
            if let Some(a) = ans.get_mut(&cur) {
                *a = (*a + MOD - c) % MOD;
            }
            cur += key;
        }
    }

    println!("{}", sum);
}

// abcdef1 => 0abcdef
// abcdef0 => 1abcdef

pub struct Scanner<R>(R);

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 9424