ISPIS | 프로그래밍의 벗 PivotOJ
PivotOJ

ISPIS

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2010 School Competition - JuniorsBOJ 3099

문제

Perica got an antique dot matrix printer that he can be control using his personal computer. While playing with his new old printer he discovered that printer recognizes three types of commands: 

  • SET(X) – This command sets character X into main memory. 
  • NEXT(X) – This command sets character X into secondary memory. 
  • WRITE – This command writes a character on the paper. The character to bi printed is read from the main memory unless previous command was NEXT. In that case, character is read from the secondary memory. 

For example, next 8 commands will write “AABAA” on the paper: 

SET(A), WRITE, WRITE, SET(B), WRITE, SET(A), WRITE, WRITE. 

After a lot of thinking, Perica discovered that he could also do it in 7 commands: 

SET(A), WRITE, WRITE, NEXT(B), WRITE, WRITE, WRITE. 

Given a sequence of characters, write a program that will calculate the minimum number of commands needed to print that sequence. 

Note: First command has to be SET. 

입력

The first line contains the sequence of characters to be printed. The sequence contains upper case english letters and is not longer than 10 000. 

출력

Output one integer, the minimum number of commands needed to print the sequence. 

 

힌트

SET(B), WRITE, NEXT(A), WRITE, WRITE, NEXT(C), WRITE, WRITE, SET(A), WRITE, NEXT(C), WRITE, WRITE. 

예제

예제 1

입력
NN
출력
3

예제 2

입력
IOIX
출력
7

예제 3

입력
BABCBACA
출력
13
코드를 제출하려면 로그인하세요.