int main() { scanf("%s", buffer + 1); n = strlen(buffer + 1); SuffixTree *tree = new SuffixTree; for (int i = 1; buffer[i]; i++) { tree->append(buffer[i] - 'a' + 1); } // for tree->append(SuffixTree::EOFCHAR); tree->sort(sa); for (int i = 1; i <= n; i++) { sa[i] = sa[i + 1]; } // for for (int i = 1; i <= n; i++) { rnk[sa[i]] = i; } // for int j = 0; for (int i = 1; i <= n; i++) { if (rnk[i] == 1) continue; j--; if (j < 0) j = 0; while (buffer[sa[rnk[i]] + j] == buffer[sa[rnk[i] - 1] + j]) { j++; } // while lcp[rnk[i]] = j; } // for for (int i = 1; i <= n; i++) { printf("%d ", sa[i]); } // for printf("\n"); for (int i = 2; i <= n; i++) { printf("%d ", lcp[i]); } // for printf("\n"); return 0; } // function main
int main() { // freopen("subst1.in", "r", stdin); // freopen("subst1.out", "w", stdout); scanf("%s", buf); n = strlen(buf); SuffixTree *tree = new SuffixTree; for (size_t pos = 0; buf[pos]; pos++) { tree->append(buf[pos] - 'A'); } // for tree->append(EOFCHAR); printf("%lld\n", tree->solve() - n - 1); return 0; } // function main