Problem:
Score : 1100 points

Problem Statement

We will call a string that can be obtained by concatenating two equal strings an even string.
For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.

For a non-empty string S, we will define f(S) as the shortest even string that can be obtained by appending one or more characters to the end of S.
For example, f(abaaba)=abaababaab.
It can be shown that f(S) is uniquely determined for a non-empty string S.

You are given an even string S consisting of lowercase English letters.
For each letter in the lowercase English alphabet, find the number of its occurrences from the l-th character through the r-th character of f^{10^{100}} (S).

Here, f^{10^{100}} (S) is the string f(f(f( ... f(S) ... ))) obtained by applying f to S 10^{100} times.

Constraints

2 \leq |S| \leq 2\times 10^5

1 \leq l \leq r \leq 10^{18}

S is an even string consisting of lowercase English letters.

l and r are integers.

Input

Input is given from Standard Input in the following format:

S
l r

Output

Print 26 integers in a line with spaces in between.
The i-th integer should be the number of the occurrences of the i-th letter in the lowercase English alphabet from the l-th character through the r-th character of f^{10^{100}} (S).

Sample Input 1

abaaba
6 10

Sample Output 1

3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Since f(abaaba)=abaababaab, the first ten characters in f^{10^{100}}(S) is also abaababaab. Thus, the sixth through the tenth characters are abaab. In this string, a appears three times, b appears twice and no other letters appear, and thus the output should be 3 and 2 followed by twenty-four 0s.

Sample Input 2

xx
1 1000000000000000000

Sample Output 2

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000000000000000 0 0

Sample Input 3

vgxgpuamkvgxgvgxgpuamkvgxg
1 1000000000000000000

Sample Output 3

87167725689669676 0 0 0 0 0 282080685775825810 0 0 0 87167725689669676 0 87167725689669676 0 0 87167725689669676 0 0 0 0 87167725689669676 141040342887912905 0 141040342887912905 0 0

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn error_function(a: &Vec<usize>) -> Vec<usize> {
    let n = a.len();
    let mut err: Vec<usize> = vec![0; n+1];

    for i in 2..n+1 {
        let mut now = err[i-1];
        while now > 0 && a[i-1] != a[now] {
            now = err[now];
        }
        if a[i-1] == a[now] {
            err[i] = now + 1;
        } else {
            err[i] = 0;
        }
    }
    err
}

fn compute(s: &Vec<usize>, c: usize, l: usize) -> Vec<usize> {
    let n = s.len();
    let mut ret = vec![0; 26];
    let mut par = vec![0; 26];
    if n % c == 0 {
        for i in 0..n {
            par[s[i]] += 1;
        }
        let cn = l / n;
        for i in 0..26 {
            ret[i] = par[i] * cn;
        }
        for i in 0..l%c {
            ret[s[i]] += 1;
        }
    } else {
        let mut len = vec![0; 120];
        let mut vec = vec![vec![0; 26]; 120];
        for i in 0..n {
            vec[0][s[i]] += 1;
            vec[1][s[i]] += 1;
        }
        for i in 0..c {
            vec[1][s[i]] += 1;
        }

        len[0] = n;
        len[1] = n + c;
        for i in 2..len.len() {
            len[i] = len[i-1] + len[i-2];
            for j in 0..26 {
                vec[i][j] = vec[i-1][j] + vec[i-2][j];
            }
            if len[i] >= l {
                return count(i, l, &len, &vec, &s)
            }
        }
    }
    ret
}

fn count(level: usize, head: usize, len: &Vec<usize>, vec: &Vec<Vec<usize>>, s: &Vec<usize>) -> Vec<usize> {
    let mut ret = vec![0; 26];
    if level == 0 {
        for i in 0..head {
            ret[s[i]] += 1;
        }
        ret
    } else if level == 1 {
        let n = s.len();
        for i in 0..head {
            ret[s[i%n]] += 1;
        }
        ret
    } else {
        if head <= len[level-1] {
            count(level-1, head, len, vec, s)
        } else {
            let x = count(level-2, head - len[level-1], len, vec, s);
            for i in 0..26 {
                ret[i] += vec[level-1][i];
                ret[i] += x[i];
            }
            ret
        }
    }
}

fn main() {
    let s: String = read();
    let s = s.into_bytes();
    let mut s: Vec<usize> = s.into_iter().map(|x| (x - 'a' as u8) as usize).collect();
    let n = s.len();
    let s = s.split_off(n / 2);

    let (l, r): (usize, usize) = read();
    let n = s.len();
    let err = error_function(&s);
    let cycle = n - err[err.len()-1];

    let ll = compute(&s, cycle, l-1);
    let rr = compute(&s, cycle, r);

    for i in 0..26 {
        if i >= 1 {
            print!(" ");
        }
        print!("{}", rr[i] - ll[i]);
    }
    println!();
}