function solution(s) {
let answer = s.length;
for (let unit=1; unit<=Math.floor(s.length/2); unit++) {
let str = '';
let now = s.slice(0, unit)
let cnt = 1;
for (let i=unit; i<s.length; i+=unit) {
if (s.slice(i, i + unit) !== now) {
str += (cnt === 1 ? '' : String(cnt)) + now;
now = s.slice(i, i + unit);
cnt = 1;
continue;
}
cnt++;
}
str += (cnt === 1 ? '' : String(cnt)) + now;
if (str.length < answer) answer = str.length;
}
return answer;
}