using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CompProgLib;

namespace ALDS1_15_D
{
    public class Program

    {
        public static void Main(string[] args)
        {
            string line = ReadSt();
            HuffmanCoding hc = new HuffmanCoding(line);

            int res = 0;
            for (int i = 0 ; i < line.Length ; i++)
            {
                res += hc.Nodes[line[i]].CodeInfo.CodeSize;
            }

            Console.WriteLine(res.ToString());
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}

namespace CompProgLib
{
    public class HuffmanCoding
    {
        public class CodeInfo
        {
            public int Code { get; private set; }
            public int CodeSize { get; private set; }

            public CodeInfo(int code, int codeSize)
            {
                this.Code = code;
                this.CodeSize = codeSize;
            }
        }

        public class Node : IComparable<Node>
        {
            internal char Value { get; private set; }
            internal int Occurrence { get; private set; }
            internal List<Node> Children { get; private set; }
            public CodeInfo CodeInfo { get; internal set; }

            public Node(char v1, int v2)
            {
                this.Value = v1;
                this.Occurrence = v2;
            }

            public Node(char v1, int v2, Node n1, Node n2) : this(v1, v2)
            {
                Children = new List<Node>();
                if (n1 != null) Children.Add(n1);
                if (n2 != null) Children.Add(n2);
            }

            public void IncrementOccurrence() { Occurrence++; }
            public int CompareTo(Node other) { return other.Occurrence - Occurrence; }
        }

        public string Target { get; set; }
        public Dictionary<char, Node> Nodes { get; private set; }

        public HuffmanCoding(string s)
        {
            Target = s;
            createValue2Code();
        }

        private void createValue2Code()
        {
            // 各バイト値の発生回数を数える
            Nodes = new Dictionary<char, Node>();
            for (int i = 0 ; i < Target.Length ; i++)
            {
                if (!Nodes.ContainsKey(Target[i]))
                {
                    Nodes.Add(Target[i], new Node(Target[i], 1));
                }
                else
                {
                    Nodes[Target[i]].IncrementOccurrence();
                }
            }

            // ハフマン木を作成
            PriorityQueue<Node> queue = new PriorityQueue<Node>();
            foreach (var item in Nodes) { queue.Enqueue(item.Value); }

            if (queue.Count == 1)
            {
                Node n1 = queue.Dequeue();
                Nodes[n1.Value].CodeInfo = new CodeInfo(1, 1);
            }
            else
            {
                while (queue.Count > 1)
                {
                    Node n1 = queue.Dequeue();
                    Node n2 = queue.Dequeue();
                    queue.Enqueue(new Node('\0', n1.Occurrence + n2.Occurrence, n1, n2));
                }

                Node root = queue.Dequeue();
                // 深さ優先探索でバイト値→符号情報を作成
                dfs(root, 0, 0);
            }           
        }

        private void dfs(Node node, int code, int codeSize)
        {
            if (node.Children == null)
            {
                Nodes[node.Value].CodeInfo = new CodeInfo(code, codeSize);
            }
            else
            {
                dfs(node.Children[0], code << 1, codeSize + 1);
                dfs(node.Children[1], (code << 1) + 1, codeSize + 1);
            }
        }
    }
}

namespace CompProgLib
{
    public class PriorityQueue<T> where T : IComparable<T>

    {

        private List<T> Buffer { get; set; }

        public int Count { get { return Buffer.Count; } }

        public PriorityQueue() { Buffer = new List<T>(); }
        public PriorityQueue(int capacity) { Buffer = new List<T>(capacity); }


        /// <summary>
        /// ヒープ化されている配列リストに新しい要素を追加する。
        /// </summary>
        public void Enqueue(T item)
        {
            int n = Buffer.Count;
            Buffer.Add(item);

            while (n != 0)
            {
                int i = (n - 1) / 2;
                if (Buffer[n].CompareTo(Buffer[i]) > 0)
                {
                    T tmp = Buffer[n]; Buffer[n] = Buffer[i]; Buffer[i] = tmp;
                }
                n = i;
            }
        }

        /// <summary>
        /// ヒープから最大値を取り出し、削除する。
        /// </summary>
        public T Dequeue()
        {
            T ret = Buffer[0];
            int n = Buffer.Count - 1;
            Buffer[0] = Buffer[n];
            Buffer.RemoveAt(n);

            for (int i = 0, j ; (j = 2 * i + 1) < n ;)
            {
                if ((j != n - 1) && (Buffer[j].CompareTo(Buffer[j + 1]) < 0))
                    j++;
                if (Buffer[i].CompareTo(Buffer[j]) < 0)
                {
                    T tmp = Buffer[j]; Buffer[j] = Buffer[i]; Buffer[i] = tmp;
                }
                i = j;
            }
            return ret;
        }

        /// <summary>
        /// ヒープから最大値を参照する。
        /// </summary>
        public T Peek()
        {
            if (Count == 0) throw new InvalidOperationException();
            return this.Buffer[0];
        }
    }
}


Measured memory_bytes: 20020