# ANUSAR - Editorial

**URL:** <https://discuss.codechef.com/t/anusar-editorial/5471>\
**Category:** editorial\
**Tags:** cook46, editorial, medium-hard, segment-tree, stack, suffix-array, suffix-trees, disjoint-set-union\
**Created:** [May 19, 2014, 12:24am UTC](https://discuss.codechef.com/t/anusar-editorial/5471 "2014-05-19T00:24:35Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mmaxio](https://discuss.codechef.com/user_avatar/discuss.codechef.com/mmaxio/32/24644_2.png) [@mmaxio](https://discuss.codechef.com/u/mmaxio)\
**Post date:** [May 19, 2014, 12:37am UTC](https://discuss.codechef.com/t/anusar-editorial/5471/2 "2014-05-19T00:37:31Z")

</div>

There is also rather easy solution using suffix automaton. Namely, for each state _v_ you know how many substrings correspond to _v_ and how many times each of them occurs in the string(number of paths from the start to _v_ and from _v_ to the end, respectively). Then you just multiply something and count some partial sums 😃

Also, you must take care of multiple final states in the automaton, but it’s all details.

---

_[View the full topic](https://discuss.codechef.com/t/anusar-editorial/5471)._
