# CodeForces 731A Night at the Museum

A. Night at the Museum

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he receivedembosser and was to take stock of the whole exposition.

Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:

After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.

Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.

Input

The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.

Output

Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.

Examples

input

`zeus`

output

`18`

input

`map`

output

`35`

input

`ares`

output

34

```#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>

using namespace std;
char a[105];
int main()
{
char now;
scanf("%s",a);
now='a';
int ans=0;
for(int i=0;a[i];i++)
{
ans+=min(abs(a[i]-now),min(abs(a[i]+26-now),abs(now+26-a[i])));
now=a[i];
}
printf("%d\n",ans);
return 0;
}```

0 条评论

• ### CodeForces 24D Broken robot （概率DP）

D. Broken robot time limit per test 2 seconds memory limit per test 256 me...

• ### CodeForces Roads not only in Berland(并查集)

H - Roads not only in Berland Time Limit:2000MS     Memory Limit:262144KB    ...

• ### POJ 3150 Cellular Automaton（矩阵快速幂）

Cellular Automaton Time Limit: 12000MS Memory Limit: 65536K Total Submis...

• ### 步进式的框架解释如何解决约束满足问题（CS AI）

我们以逻辑网格难题的用例探讨逐步解释如何解决约束满足问题的问题。更具体地说，我们研究一种以易于理解的方式解释传播过程中可以采取的推理步骤的问题。因此，我们旨在为...

• ### 自动驾驶共享多模态轨迹预测（CS AI）

本文提出了一种用于预测在高度交互环境中交通未来轨迹的预测框架。基于自动驾驶车辆均配备有各类传感器（例如：LiDAR扫描器，RGB摄像扥）的现实条件下，本研究旨在...

• ### A Fast QTMT Partition Decision Strategy for VVC Intra Prediction

Different from the traditional quaternary tree (QT) structure utilized in the pr...

• ### 十大革命性理论(Top 10 revolutionary scientifictheories)中英版(19k字)

本篇《十大革命性理论》(Top 10 revolutionary scientific theories |Science News)中英文对照版AB，把原文倒...

• ### 追踪接触者以控制COVID-19大流行（CS SI）

控制 COVID-19大流行需要大量减少接触，主要是通过实施行动控制达到强制隔离的水平。 这导致了经济的大部分崩溃。这种疾病的携带者大约在接触病毒后3天具有传染...

• ### 【论文推荐】最新6篇图像分割相关论文—隐马尔可夫随机场、级联三维全卷积、信号处理、全卷积网络、多源域适应、循环分割

【导读】专知内容组整理了最近六篇图像分割（Image Segmentation）相关文章，为大家进行介绍，欢迎查看! 1.Combination of Hidd...

• ### Instant Messaging at LinkedIn: Scaling to 10000 of Connections

We recently introduced Instant Messaging on LinkedIn, complete with typing indic...