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 C++14 (Clang 3.8.0) (judge verdict: Wrong Answer)

#include <iostream>
#include <vector>

std::vector<int> KMP(const std::string &s) {
  std::vector<int> ret(s.size() + 1);
  ret[0] = -1;
  int j = -1;
  for (unsigned i = 0; i < s.size(); ++i) {
    while (j >= 0 && s[i] != s[j]) { j = ret[j]; }
    ++j;
    ret[i + 1] = j;
  }
  ret[0] = 0;
  return ret;
}

std::vector<unsigned> period(const std::string &s) {
  auto x = KMP(s);
  std::vector<unsigned> ret(s.size());
  for (unsigned i = 0; i < s.size(); ++i) {
    ret[i] = i + 1 - x[i + 1];
  }
  return ret;
}

int main() {
  std::string s;
  std::cin >> s;
  auto lens = s.size();
  while (s.size() > lens / 2) { s.pop_back(); }
  unsigned long long l, r;
  std::cin >> l >> r;
  auto per = period(s).back();
  if (s.size() % per == 0) {
    std::vector<unsigned long long> cnt('z' - 'a' + 1, 0);
    unsigned long long lq = (l - 1) / per;
    unsigned long long lr = (l - 1) % per;
    unsigned long long rq = r / per;
    unsigned long long rr = r % per;
    for (unsigned i = 0; i < per; ++i) {
      cnt[s[i] - 'a'] += rq - lq;
    }
    for (unsigned i = 0; i < rr; ++i) {
      ++cnt[s[i] - 'a'];
    }
    for (unsigned i = 0; i < lr; ++i) {
      --cnt[s[i]];
    }
    for (unsigned i = 0; i < cnt.size(); ++i) {
      std::cout << cnt[i] << " ";
    }
    std::cout << std::endl;
  } else {
    std::vector<unsigned long long> len;
    len.push_back(s.size());
    len.push_back(s.size() + per);
    while (len.back() < r) {
      auto x = len[len.size() - 1];
      auto y = len[len.size() - 2];
      len.push_back(x + y);
    }
    std::vector<unsigned long long> cnt_s('z' - 'a' + 1, 0);
    for (auto &c : s) { ++cnt_s[c - 'a']; }
    std::vector<unsigned long long> cnt_gs('z' - 'a' + 1, 0);
    for (unsigned i = 0; i < cnt_s.size(); ++i) { cnt_gs[i] = cnt_s[i]; }
    for (unsigned i = 0; i < per; ++i) { ++cnt_gs[s[i] - 'a']; }
    for (int i = 0; i <= 'z' - 'a'; ++i) {
      std::vector<unsigned long long> cnt;
      cnt.push_back(cnt_s[i]);
      cnt.push_back(cnt_gs[i]);
      for (unsigned j = 2; j < len.size(); ++j) {
        auto x = cnt[cnt.size() - 1];
        auto y = cnt[cnt.size() - 2];
        cnt.push_back(x + y);
      }
      unsigned long long ans = 0;
      auto rr = r;
      for (auto j = len.size() - 1; j > 1; --j) {
        if (len[j] > rr) { continue; }
        rr -= len[j];
        ans += cnt[j];
      }
      if (rr >= len[1]) {
        rr -= len[1];
        ans += cnt[1];
        for (unsigned j = 0; j < rr; ++j) {
          if (s[j] - 'a' == i) { ++ans; }
        }
      } else {
        for (unsigned j = 0; j < s.size() && rr; ++j) {
          --rr;
          if (s[j] - 'a' == i) { ++ans; }
        }
        for (unsigned j = 0; j < rr; ++j) {
          if (s[j] - 'a' == i) { ++ans; }
        }
      }
      auto ll = l - 1;
      for (auto j = len.size() - 1; j > 1; --j) {
        if (len[j] > ll) { continue; }
        ll -= len[j];
        ans -= cnt[j];
      }
      if (ll >= len[1]) {
        ll -= len[1];
        ans -= cnt[1];
        for (unsigned j = 0; j < ll; ++j) {
          if (s[j] - 'a' == i) { --ans; }
        }
      } else {
        for (unsigned j = 0; j < s.size() && ll; ++j) {
          --ll;
          if (s[j] - 'a' == i) { --ans; }
        }
        for (unsigned j = 0; j < ll; ++j) {
          if (s[j] - 'a' == i) { --ans; }
        }
      }
      std::cout << ans << " ";
    }
    std::cout << std::endl;
  }
  return 0;
}