{"problem":{"name":"A. Night at the Museum","description":{"content":"Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received _embosser_ and was to take stock of the whole exposition. _Embosser_","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF731A"},"statements":[{"statement_type":"Markdown","content":"Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received _embosser_ and was to take stock of the whole exposition.\n\n_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:\n\n<center>![image](https://espresso.codeforces.com/f9a6625d44375aa879555a962abab58252e0f103.png)</center>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_'.\n\nOur 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.\n\n## Input\n\nThe 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.\n\n## Output\n\nPrint one integer — the minimum number of rotations of the wheel, required to print the name given in the input.\n\n[samples]\n\n## Note\n\n<center>![image](https://espresso.codeforces.com/7a9f692be97294f6f0dedd91b5e5794fcea7c621.png)</center>To print the string from the first sample it would be optimal to perform the following sequence of rotations:\n\n1.  from '_a_' to '_z_' (1 rotation counterclockwise),\n2.  from '_z_' to '_e_' (5 clockwise rotations),\n3.  from '_e_' to '_u_' (10 rotations counterclockwise),\n4.  from '_u_' to '_s_' (2 counterclockwise rotations).\n\nIn total, 1 + 5 + 10 + 2 = 18 rotations are required.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Grigoriy 像一部著名喜剧电影的主角一样，找到了一份博物馆夜间保安的工作。在第一个夜晚，他收到了一个_凸印机_，并需要清点整个展览。\n\n_凸印机_是一种可以“打印”塑料带文本的特殊设备。文本按顺序逐字符打印。该设备由一个带有小写英文字母排列成环的轮子、一个指向当前字母的固定指针以及一个打印所选字母的按钮组成。每次移动允许将字母轮顺时针或逆时针旋转一步。初始时，固定指针指向字母 '_a_'。其他字母的排列如图所示：\n\nGrigoriy 在将新物品加入库存后，必须在其塑料带上打印名称并将其附着到相应的展品上。不需要将轮子转回初始位置（指针指向 '_a_'）。\n\n我们的英雄担心某些展品可能会复活并攻击他，因此他希望尽可能快地打印名称。请帮助他：对于给定的字符串，求出打印它所需的轮子最小旋转次数。\n\n输入仅一行，包含某个展品的名称——一个非空字符串，长度不超过 #cf_span[100] 个字符。保证字符串仅由小写英文字母组成。\n\n请输出一个整数——打印输入中给出的名称所需的轮子最小旋转次数。\n\n \n\n对于第一个样例中的字符串，最优的旋转序列如下：\n\n## Input\n\nThe only line of input contains the name of some exhibit — the non-empty string consisting of no more than #cf_span[100] characters. It's guaranteed that the string consists of only lowercase English letters.\n\n## Output\n\nPrint one integer — the minimum number of rotations of the wheel, required to print the name given in the input.\n\n[samples]\n\n## Note\n\n   要打印第一个样例中的字符串，最优的旋转序列如下：\n\n从 '_a_' 到 '_z_'（#cf_span[1] 次逆时针旋转），\n从 '_z_' 到 '_e_'（#cf_span[5] 次顺时针旋转），\n从 '_e_' 到 '_u_'（#cf_span[10] 次逆时针旋转），\n从 '_u_' 到 '_s_'（#cf_span[2] 次逆时针旋转）。\n\n总共需要 #cf_span[1 + 5 + 10 + 2 = 18] 次旋转。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"Let the alphabet be arranged in a circle of 26 letters, labeled $ a, b, c, \\dots, z $, with positions indexed from 0 to 25, where $ a \\leftrightarrow 0 $, $ b \\leftrightarrow 1 $, ..., $ z \\leftrightarrow 25 $.\n\nLet $ s = s_1 s_2 \\dots s_n $ be the input string of length $ n \\leq 100 $, where each $ s_i \\in \\{a, b, \\dots, z\\} $.\n\nLet $ p_0 = 0 $ be the initial position of the pointer (corresponding to letter 'a').\n\nFor each character $ s_i $, let $ c_i \\in \\{0, 1, \\dots, 25\\} $ be its numeric position in the alphabet.\n\nDefine the cost to move from current position $ p $ to target position $ c $ as:\n$$\n\\text{dist}(p, c) = \\min\\left( |p - c|, 26 - |p - c| \\right)\n$$\n\nLet $ p_i $ be the position of the pointer after printing the $ i $-th character. Then:\n- $ p_0 = 0 $\n- For $ i = 1 $ to $ n $:  \n  $ p_i = c_i $  \n  and the cost for step $ i $ is $ \\text{dist}(p_{i-1}, c_i) $\n\nThe total minimum number of rotations is:\n$$\n\\sum_{i=1}^{n} \\min\\left( |p_{i-1} - c_i|, 26 - |p_{i-1} - c_i| \\right)\n$$\n\n**Objective:** Compute the above sum.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF731A","tags":["implementation","strings"],"sample_group":[["zeus","18"],["map","35"],["ares","34"]],"created_at":"2026-03-03 11:00:39"}}