using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var s = ReadLine();
        var l = new char[] { 'a', ' ', 'b', 'c' };
        var x = 1000000;
        var y = 1000000;
        var set = new HashSet<long>{ Key(x, y) };
        var mx = new int[] { -1, 0, 0, 1 };
        var my = new int[] { 0, -1, 1, 0 };
        foreach (var si in s)
        {
            var pos = Pos(l, si);
            x += mx[pos];
            y += my[pos];
            set.Add(Key(x, y));
            if (l[1] == ' ')
            {
                if (pos == 0) (l[0], l[1], l[2], l[3]) = (l[2], l[3], l[1], l[0]);
                else if (pos == 2) (l[0], l[1], l[2], l[3]) = (l[0], l[2], l[1], l[3]);
                else (l[0], l[1], l[2], l[3]) = (l[3], l[0], l[1], l[2]);
            }
            else
            {
                if (pos == 0) (l[0], l[1], l[2], l[3]) = (l[1], l[2], l[3], l[0]);
                else if (pos == 1) (l[0], l[1], l[2], l[3]) = (l[0], l[2], l[1], l[3]);
                else (l[0], l[1], l[2], l[3]) = (l[3], l[2], l[0], l[1]);
            }
        }
        WriteLine(set.Count);
    }
    static int Pos(char[] a, char c)
    {
        for (var i = 0; i < a.Length; ++i) if (a[i] == c) return i;
        return -1;
    }
    static long Key(int x, int y)
    {
        return x * 10_000_000L + y;
    }
}