Number of distinct substrings 2

Count how many different contiguous substrings appear in the given lowercase string of length up to 1,000,000.

Medium7String matchingSortingTrieNo attempts yetTime limit5sMemory limit256 MB

Problem

Given a string SS, write a program that counts how many distinct substrings SS has.

A substring is a contiguous piece cut out of SS, and its length must be at least 1.

For example, if SS is ababc, the substrings are a, b, a, b, c, ab, ba, ab, bc, aba, bab, abc, abab, babc, ababc, and 12 of them are distinct.

Input

The first line contains the string SS. SS consists of lowercase letters only, and its length is at least 1 and at most 1,000,000.

Output

Print the number of distinct substrings of SS on the first line.