import java.util.*;
import java.io.*;

public class strange_dk {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer stok;

    String nextToken() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            stok = new StringTokenizer(s);
        }
        return stok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    char nextChar() throws IOException {
        return (char) (br.read());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }

    class Peace {
        char c;
        int x;

        Peace(char c, int x) {
            this.c = c;
            this.x = x;
        }
    }
    class Pair implements Comparable<Pair> {
        int x;
        int y;

        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }


        @Override
        public int compareTo(Pair o) {
            if (x == o.x) {
                return y - o.y;
            }
            return x - o.x;
        }
    }

    private void solve() throws IOException {
        String s = nextLine();
        ArrayList<Peace> a = new ArrayList<Peace>();
        int q = 0;
        ArrayList<Integer>[] letter = new ArrayList[26];
        for (int i1 = 0; i1 < 26; i1++) {
            letter[i1] = new ArrayList<Integer>();
        }

        while (q < s.length()) {
            int j = q;
            while (j < s.length() && s.charAt(j) == s.charAt(q)) {
                j++;
            }
            letter[s.charAt(q) - 'a'].add(a.size());
            a.add(new Peace(s.charAt(q), j - q));
            q = j;
        }

        ArrayList<Pair>[][] rects = new ArrayList[26][26];
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < 26; j++) {
                rects[i][j] = new ArrayList<Pair>();
            }
        }
        for (int i = 0; i < a.size() - 1; i++) {
            rects[a.get(i).c - 'a'][a.get(i + 1).c - 'a'].add(new Pair(a.get(i).x, a.get(i+1).x));
        }
        long ans = 0;
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < 26; j++) {
                if (rects[i][j].size() == 0) continue;
                Collections.sort(rects[i][j]);
                Stack<Pair> stack = new Stack<Pair>();
                for (int w = 0; w < rects[i][j].size(); w++) {
                    while (stack.size() > 0 && stack.peek().y < rects[i][j].get(w).y) {
                        stack.pop();
                    }
                    stack.add(rects[i][j].get(w));
                }
                ArrayList<Pair> arrstack = new ArrayList<Pair>(stack);
                //System.err.println(arrstack.size());
                long curans = 0;
                curans += (arrstack.get(0).y + 0L) * (arrstack.get(0).x);
                for (int w = 1; w < arrstack.size(); w++) {
                    curans += (arrstack.get(w).x - arrstack.get(w - 1).x) * (arrstack.get(w).y + 0L);
                }
                //System.err.println(curans);
                ans += curans;

            }
        }

        int[] max = new int[26];
        for (int i = 0; i < a.size(); i++) {
            max[a.get(i).c - 'a'] = Math.max(max[a.get(i).c - 'a'], a.get(i).x);
        }
        for (int i = 0; i < 26; i++) {
            ans += max[i];
        }
        out.println(ans);


    }



    void run() throws IOException {
        br = new BufferedReader(new FileReader("strange.in"));
        out = new PrintWriter("strange.out");
        //br = new BufferedReader(new InputStreamReader(System.in));
        //out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        // Locale.setDefault(Locale.US);
        new strange_dk().run();
    }
}