PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000202. Biến xâu thành các cặp giống nhau (Get an Even String)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Biến xâu thành các cặp giống nhau (Get an Even String)

Get an Even String

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A string is called even if it can be partitioned into adjacent pairs of identical characters. Equivalently, its length is even and characters at each odd position 1,3,5,…1,3,5,\ldots match their immediate successors. The empty string is even.

For example, aa, aabb, and ttcccc are even, while aaa and abba are not.

Given a lowercase English string ss, you may delete characters at arbitrary positions while preserving the order of those that remain. Find the minimum number of deletions needed to obtain an even string. Do not output the resulting string.

Input

The only line contains a nonempty lowercase English string ss.

Output

Print one integer: the fewest deletions needed to make the remaining string a concatenation of equal-character pairs.

Subtasks

  • Subtask 1 (20 points): 1≤∣s∣≤91\le|s|\le9; Every character of ss is in a–z.
  • Subtask 2 (30 points): 1≤∣s∣≤20001\le|s|\le2000; Every character of ss is in a–z.
  • Subtask 3 (50 points): 1≤∣s∣≤2⋅1051\le|s|\le2\cdot10^5; Every character of ss is in a–z.

Examples

Input

aabbdabdccc

Output

3

Explanation

The input contains the 1111 characters a a b b d a b d c c c. Deleting original positions 66 (a), 77 (b), and 99 (c) leaves aabbddcc, four valid pairs. One deletion would leave ten characters, but no such deletion yields valid pairs; two deletions leave an odd length. Therefore three deletions are minimum.