Under construction

Still being built. Things may change

Dynamic Input Tool

Time limit2sMemory limit512 MB

Summary
Find the minimum number of append-character and append-subsequence-of-current-string operations needed to build a given string from empty.
Level

Hard8 of 10

Topics
Dynamic programming, String, Greedy, Binary search
Solved
No attempts yet

Problem

CodingSlave 1.0 is a brand new text editor. There are two operations you can use to compose a string in CodingSlave 1.0:

  1. Add one character at the end of the current string.
  2. Choose a nonempty subsequence of the current string and add it at the end of the current string.

Initially, the current string is empty.

Given a word consisting of lowercase English letters, find the minimum number of operations needed to compose this string.

Input

The first line contains a string SS consisting of lowercase English letters (1≤∣S∣≤1061 \le |S| \le 10^6).

Output

Print one integer: the minimum number of operations needed to compose SS using CodingSlave 1.0.

Examples2

  1. Example 1

    Input
    aaa
    
    Expected output
    3
    
  2. Example 2

    Input
    aabaaaabaa
    
    Expected output
    5