function solution(name) {
let ans = 0;
let targetCount = 0;
const y = name.split('').map(c => {
const height = c.charCodeAt()-65;
if(height){
ans+=height < 13 ? height : 26-height;
targetCount++;
}
return height;
});
const round = [...y, ...y];
let current = y.length;
let left = current;
let right = current;
let count = 0;
while(count<targetCount){
while(!round[left]){
left--;
};
while(!round[right]) {
right++;
};
const leftDx = current-left;
const rightDx = right - current;
if(leftDx < rightDx){
ans+=leftDx;
current = left;
round[left] = 0;
}else{
ans+=rightDx;
current = right;
round[right] = 0;
}
count++;
}
return ans;
}