Icarus' Rebirth

시간 제한1초메모리 제한2048 MB

요약
첫 문자에서 마지막 문자까지 최소 걸음 수를 구한다. 한 걸음은 인접한 위치로 가거나 같은 값을 가진 가장 가까운 문자로 이동한다.
난이도

보통10점 중 7점

유형
BFS, 그래프
정답자
아직 제출이 없습니다

문제

In an attempt to escape from Crete's highest tower, where they were imprisoned, Icarus and his father Daedalus made two pairs of wings, with which they could fly away to Athens. During their flight, all was well until Icarus' hubris led him to fly too close to the sun, causing his wings to melt and him to drown in the Mediterranean Sea. Mourning the loss of his child, Daedalus now undertakes a perilous journey through the underworld to find Hades -- the god of the dead. He meets Hades and begs him to give back his son.

"Your request shall be granted, craftsman, but only if you prove yourself worthy by solving this task," says Hades. "I shall give you a word in the language of the gods. You see, the way we gods measure a word's length is different from the method you humans use. We measure the length of a word by calculating the minimum number of steps that need to be taken from the first character, to reach the last one. In a step, starting from the character with value xx at position ii, you may either go to a character with position i−1i-1 or i+1i+1, or you can go to the closest character with value xx to the left or to the right." Daedalus is a smart man, and knowing he can not solve this problem for enormous words, he asks you to write a computer program that calculates the length of any word on your magical stone tablet.

Given some word in the language of the gods, calculate its length according to the gods' way of measuring, so Daedalus can take back his beloved son Icarus.

입력

The input consists of:

  • A line with a single word ww (1≤∣w∣≤1051\leq |w|\leq 10^5). The word contains only lowercase letters from the English alphabet ('a-z').

출력

Output a single number, the length of the word ww, according to the gods' way of measuring.

예제2

  1. 예제 1

    입력
    word
    
    예상 출력
    3
    
  2. 예제 2

    입력
    adiacrac
    
    예상 출력
    3