VJEŠALA | 프로그래밍의 벗 PivotOJ
PivotOJ

VJEŠALA

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2008 National Competition #2 - JuniorsBOJ 3128

문제

Ivica is playing "Hangman" on his mobile phone. The goal of the game is to uncover letters in a secret phrase. 

Initially, all letters in the secret phrase are obscured by dashes (one for each letter). Ivica chooses which letter to uncover next; if that letter appears in the secret phrase, then all its occurrences are revealed. The game ends after Ivica guesses all the letters. 

Ivica plays this game all too often and has learned to recognize many of the phrases just by looking at the layout of the dashes. When he recognizes a phrase, Ivica wants to type it in as quickly as possible. 

To select the next letter, Ivica uses three keys; LEFT, RIGHT and OK. 

  • One letter is always displayed on screen. Initially this is the letter A. 
  • When OK is pressed, the letter displayed is selected and all its occurrences revealed. The letter remains displayed. 
  • When LEFT is pressed, the previous letter is displayed (for example, C becomes B, Z becomes A). 
  • When RIGHT is pressed, the next letter is displayed (for example, B becomes C, A becomes Z). 

Write a program that determines the smallest number of key presses Ivica needs to reveal the entire phrase, and one possible ordering of letters guessed that achieves the smallest number. 

Note: the ordering of letters is not necessarily unique. 

입력

The first and only line contains the secret phrase – at least 1 and at most 100 characters. All characters will be uppercase letters or spaces. The phrase starts and ends in a letter, and there is exactly one space between words. 

출력

On the first line, output the smallest number of key presses needed to reveal the entire phrase. 

On the second line, output an ordering which achieves that smallest number. 

힌트

In the first example, Ivica can press keys in this order: RIGHT, OK, LEFT 7 times, OK, LEFT, OK, LEFT 2 times, OK, LEFT 3 times, OK.

예제

예제 1

입력
TURBO
출력
19
BUTRO

예제 2

입력
PUTRA ZA SUTRA
출력
18
AZUTSRP

예제 3

입력
IGRA BEZ GRANICA
출력
28
AZBCEGINR
코드를 제출하려면 로그인하세요.