using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    bool Fun(int n, int m, int h, List<int> a)
    {
        int x = 0;
        while (x < n)
        {
            int y = x + 1;
            while (a[y] + m > h)
                y++;
            if (y == x + 1)
            {
                x++;
                continue;
            }

            bool f = true;
            int c = m - 1;
            for (int i = x + 1; i < y; i++)
            {
                if (a[i] + c > h)
                {
                    if (!f || a[i] > h)
                        return false;
                    c = Math.Min(c, h - a[i]);
                }

                if (c == 0)
                    f = false;
                if (f)
                    c--;
                else
                    c++;
            }

            x = y;
        }

        return true;
    }

    public void Solve()
    {
        for (int tt = ReadInt(); tt > 0; tt--)
        {
            int n = ReadInt() + 1;
            int m = ReadInt();
            int h = ReadInt();

            var a = new List<int> { int.MinValue };
            a.AddRange(ReadIntArray());
            a.Add(int.MinValue);

            Write(Fun(n, m, h, a) ? "Yes" : "No");
        }
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int t = int.Parse(Console.ReadLine());
        for (int i = 0; i < t; i++)
        {
            Solve();
        }
    }
    static void Solve()
    {
        var nkl = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nkl[0];
        var k = nkl[1]; //period
        var l = nkl[2]; //drawn limit
        var d = Console.ReadLine().Split().Select(long.Parse).ToArray();

        //0   1          k-1  k  k+1
        //k, k-1, k-2, .. 1,  0,  1, ... k - 1
        long cur = 0;
        //ヤバい時にいられる場所まで駆け抜けられるか
        for (int i = 0; i < d.Length; i++)
        {
            if (d[i] + k <= l) cur = 0;
            else
            {
                cur++;
                var limit = l - d[i];
                if (limit + k < cur)
                {
                    Console.WriteLine("No");
                    return;
                }
                //wait until
                var firstPossible = k - limit;
                cur = Max(firstPossible, cur);
            }
        }
        Console.WriteLine("Yes");
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;

using E = System.Linq.Enumerable;

internal partial class Solver {
    public void Run() {
        var t = ni();
        while (t-- > 0) {
            var n = ni();
            var k = ni();
            var l = ni();
            var d = ni(n);
            bool ans = true;
            bool increasing = false;
            int currentP = k + 1;
            foreach (var x in d) {
                // x + p <= l
                var maxP = l - x;
                if (maxP < 0) {
                    ans = false;
                    break;
                }
                if (maxP >= k) { // safe
                    currentP = k + 1;
                    increasing = false;
                } else {
                    // maxP < k
                    if (increasing) currentP++; else currentP--;
                    if (increasing) {
                        if (currentP > maxP) {
                            ans = false;
                            break;
                        }
                    } else {
                        currentP = Math.Min(currentP, maxP);
                        if (currentP == 0) increasing = true;
                    }
                }
            }
            cout.WriteLine(ans ? "Yes" : "No");
        }
    }

}

// PREWRITEN CODE BEGINS FROM HERE

static public class StringExtensions {
    static public string JoinToString<T>(this IEnumerable<T> source, string separator = " ") {
        return string.Join(separator, source);
    }
}

internal partial class Solver : Scanner {
    public static void Main() {
#if LOCAL
        byte[] inputBuffer = new byte[1000000];
        var inputStream = Console.OpenStandardInput(inputBuffer.Length);
        using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) {
            Console.SetIn(reader);
            new Solver(Console.In, Console.Out).Run();
        }
#else
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver(Console.In, Console.Out).Run();
        Console.Out.Flush();
#endif
    }

#pragma warning disable IDE0052
    private readonly TextReader cin;
    private readonly TextWriter cout;
    private readonly TextWriter cerr;
#pragma warning restore IDE0052

    public Solver(TextReader reader, TextWriter writer)
        : base(reader) {
        cin = reader;
        cout = writer;
        cerr = Console.Error;
    }

    public Solver(string input, TextWriter writer)
        : this(new StringReader(input), writer) {
    }

#pragma warning disable IDE1006
#pragma warning disable IDE0051
    private int ni() { return NextInt(); }
    private int[] ni(int n) { return NextIntArray(n); }
    private long nl() { return NextLong(); }
    private long[] nl(int n) { return NextLongArray(n); }
    private double nd() { return NextDouble(); }
    private double[] nd(int n) { return NextDoubleArray(n); }
    private string ns() { return Next(); }
    private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}

#if DEBUG
internal static class LinqPadExtension {
    public static string TextDump<T>(this T obj) {
        if (obj is IEnumerable) return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
        else return obj.ToString().Dump();
    }
    public static T Dump<T>(this T obj) {
        return LINQPad.Extensions.Dump(obj);
    }
}
#endif

public class Scanner {
    private readonly TextReader Reader;
    private readonly CultureInfo ci = CultureInfo.InvariantCulture;

    private readonly char[] buffer = new char[2 * 1024];
    private int cursor = 0, length = 0;
    private string Token;
    private readonly StringBuilder sb = new StringBuilder(1024);

    public Scanner()
        : this(Console.In) {
    }

    public Scanner(TextReader reader) {
        Reader = reader;
    }

    public int NextInt() { return checked((int)NextLong()); }
    public long NextLong() {
        var s = Next();
        long r = 0;
        int i = 0;
        bool negative = false;
        if (s[i] == '-') {
            negative = true;
            i++;
        }
        for (; i < s.Length; i++) {
            r = r * 10 + (s[i] - '0');
#if DEBUG
            if (!char.IsDigit(s[i])) throw new FormatException();
#endif
        }
        return negative ? -r : r;
    }
    public double NextDouble() { return double.Parse(Next(), ci); }
    public string[] NextArray(int size) {
        string[] array = new string[size];
        for (int i = 0; i < size; i++) {
            array[i] = Next();
        }

        return array;
    }
    public int[] NextIntArray(int size) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextInt();
        }

        return array;
    }

    public long[] NextLongArray(int size) {
        long[] array = new long[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextLong();
        }

        return array;
    }

    public double[] NextDoubleArray(int size) {
        double[] array = new double[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextDouble();
        }

        return array;
    }

    public string Next() {
        if (Token == null) {
            if (!StockToken()) {
                throw new Exception();
            }
        }
        var token = Token;
        Token = null;
        return token;
    }

    public bool HasNext() {
        if (Token != null) {
            return true;
        }

        return StockToken();
    }

    private bool StockToken() {
        while (true) {
            sb.Clear();
            while (true) {
                if (cursor >= length) {
                    cursor = 0;
                    if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
                        break;
                    }
                }
                var c = buffer[cursor++];
                if (33 <= c && c <= 126) {
                    sb.Append(c);
                } else {
                    if (sb.Length > 0) break;
                }
            }

            if (sb.Length > 0) {
                Token = sb.ToString();
                return true;
            }

            return false;
        }
    }
}

//using MetadataExtractor;
//using MetadataExtractor.Formats.Exif;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace CodeForces
{
    public static class MainClass
    {

        static int ReadIntLine()
        {
            return int.Parse(Console.ReadLine());
        }

        static void ReadInt(ref int a)
        {
            a = ReadIntArrayLine()[0];
        }

        static void ReadInts(ref int a, ref int b)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1];
        }

        static void ReadInts(ref int a, ref int b, ref int c)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d, ref int e)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3]; e = x[4];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d, ref int e, ref int f)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3]; e = x[4]; f = x[5];
        }

        static int[] ReadIntArrayLine()
        {
            char[] sep = { ' ' };
            return Console.ReadLine().Split(sep, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static void PrintLn(object obj)
        {
            Console.WriteLine(obj.ToString());
        }

        /*public static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }*/

        public static void PrintLnCollection<T>(IEnumerable<T> col)
        {
            PrintLn(string.Join(" ", col));
        }

        public static void PrintLn(params object[] v)
        {
            PrintLnCollection(v);
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static string MySubstring(this string str, int start, int finish)
        {
            if (start > finish) return "";
            return str.Substring(start, finish - start + 1);
        }

        public static string Reverse(this string str)
        {
            if (str == null) return null;

            return new string(str.ToArray().Reverse().ToArray());
        }
        public static bool IsInRange(this int a, int lb, int ub)
        {
            return (a >= lb) && (a <= ub);
        }

        private static void mergeDS(int i, int j, int[] a)
        {
            int t = a[j];
            for (int ii = 0; ii < a.Length; ii++)
            {
                if (a[ii] == t)
                    a[ii] = a[i];
            }
        }

        private static T MyMax<T>(params T[] a)
        {
            return a.Max();
        }

        private static T MyMin<T>(params T[] a)
        {
            return a.Min();
        }

        private static int[] GetPrimesLessThan(int x)
        {
            if (x < 2)
                return new int[0];

            int[] a = new int[x];

            a[0] = 1; a[1] = 1;

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == 0)
                    for (int j = 2 * i; j < a.Length; j += i)
                    {
                        a[j] = 1;
                    }
            }

            var abc = new List<int>(x);

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == 0)
                    abc.Add(i);
            }

            return abc.ToArray();
        }

        private static int FindNearestLEQElementInTheArray(int[] a, int startIndex, int endIndex, int target)
        {
            if (startIndex == endIndex)
            {
                if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            if (startIndex + 1 == endIndex)
            {
                if (a[endIndex] <= target)
                    return endIndex;
                else if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            int mid = (startIndex + endIndex) / 2;
            if (target == a[mid])
                return mid;
            else if (target < a[mid])
                return FindNearestLEQElementInTheArray(a, startIndex, mid - 1, target);
            else
                return FindNearestLEQElementInTheArray(a, mid, endIndex, target);
        }

        private static int FindNearestLEQElementInTheArray(int[] a, int target)
        {
            return FindNearestLEQElementInTheArray(a, 0, a.Length - 1, target);
        }

        private static int FindRightMostLEQElementInTheArray(int[] a, int startIndex, int endIndex, int target)
        {
            if (startIndex == endIndex)
            {
                if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            if (startIndex + 1 == endIndex)
            {
                if (a[endIndex] <= target)
                    return endIndex;
                else if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            int mid = (startIndex + endIndex) / 2;
            if (target < a[mid])
                return FindRightMostLEQElementInTheArray(a, startIndex, mid - 1, target);
            else
                return FindRightMostLEQElementInTheArray(a, mid, endIndex, target);
        }

        private static int FindRightMostLEQElementInTheArray(int[] a, int target)
        {
            return FindRightMostLEQElementInTheArray(a, 0, a.Length - 1, target);
        }

        private static int gcd(int a, int b)
        {

            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        //----------------------------------------------------------------------------

        static string GetSha1(string filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            using (BufferedStream bs = new BufferedStream(fs))
            {
                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    byte[] hash = sha1.ComputeHash(bs);
                    StringBuilder formatted = new StringBuilder(2 * hash.Length);
                    foreach (byte b in hash)
                    {
                        formatted.AppendFormat("{0:X2}", b);
                    }

                    return formatted.ToString();
                }
            }
        }

        static bool canFit(int a1, int b1, int a2, int b2)
        {
            int[] r1 = { a1, b1 };
            int[] r2 = { a2, b2 };

            Array.Sort(r1);
            Array.Sort(r2);

            bool ans = (r1[0] <= r2[0]) && (r1[1] <= r2[1]);

            return ans;

        }

        class Pair
        {
            public int first { get; set; }
            public int second { get; set; }
        }

        class Coord
        {
            public int x;
            public int y;
            public double d;
        }

        public static double dist(int x1, int y1, int x2, int y2)
        {
            int dx = x2 - x1;
            int dy = y2 - y1;

            return Math.Sqrt(dx * dx + dy * dy);

        }
        static void Main(string[] args)
        {
            //Console.Out.Flush();

            int tt = ReadIntLine();

            while (tt-- > 0)
            {
                int n = 0, k = 0, l = 0;
                ReadInts(ref n, ref k, ref l);

                var d = ReadIntArrayLine();

                var safe = new int[d.Length];
                //var safe2 = new int[d.Length];

                bool bad = false;
                for (int i = 0; i < n; i++)
                {
                    safe[i] = Math.Min(l - d[i], k);
                    if (safe[i]<0)
                    {
                        bad = true;
                        break;
                    }
                }

                if (bad)
                {
                    PrintLn("NO");
                    continue;
                }

                int gs = -safe[n-1];
                int ge = -gs;
                bool pos = true;

                for (int i = n-2; i >=0; i--)
                {
                    if (safe[i]==k)
                    {
                        gs = -k;
                        ge = k;
                    }
                    else
                    {
                        gs--;
                        ge--;

                        if (gs.IsInRange(-safe[i],safe[i]) || ge.IsInRange(-safe[i], safe[i])
                            || (-safe[i]).IsInRange(gs,ge) || safe[i].IsInRange(gs,ge))
                        {
                            gs = Math.Max(gs, -safe[i]);
                            ge = Math.Min(ge, safe[i]);
                        }
                        else
                        {
                            pos = false;
                            break;
                        }
                    }

                }

                if (pos)
                    PrintLn("Yes");
                else
                    PrintLn("NO");

            } //while tt

        } //main
          //ReadInts(ref a, ref b);
          //int n = ReadIntLine();
          //int[] a = ReadIntArrayLine();
          // li.Sort((a, b) => b.CompareTo(a)); DESC

    }

}


using System;
using System.IO;
using System.Text;

namespace Door_Frames
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static int Solve(string[] args)
        {
            int n = Next();
            int a = Next();
            int b = Next();

            int max = 1 << 6;

            int min = 6;
            for (int i = 0; i < max; i++)
            {
                if (SparseBitcount(i) == 2)
                {
                    int ii = i;
                    int count = 1;
                    int remain = n;
                    for (int j = 0; j < 6; j++)
                    {
                        if ((ii & 1) == 1)
                        {
                            if (remain >= b)
                            {
                                remain -= b;
                            }
                            else
                            {
                                count++;
                                remain = n - b;
                            }
                        }
                        else
                        {
                            if (remain >= a)
                            {
                                remain -= a;
                            }
                            else
                            {
                                count++;
                                remain = n - a;
                            }
                        }
                        ii >>= 1;
                    }
                    min = Math.Min(min, count);
                }
            }

            return min;
        }

        private static int SparseBitcount(int n)
        {
            int count = 0;
            while (n != 0)
            {
                count++;
                n &= (n - 1);
            }
            return count;
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;

namespace Обрамление_дверей
{
    class Program
    {
        static void Main(string[] args)
        {
            int barLength = int.Parse(Console.ReadLine());
            int borderLength = int.Parse(Console.ReadLine());
            int upperBorderLength = int.Parse(Console.ReadLine());

            int scrap, barNum = 0, aNum=0,bNum=0;

            while (true)
            {
                if (upperBorderLength <= borderLength && bNum < 2 || aNum >= 4 && bNum < 2)
                {
                    scrap = barLength;
                    barNum++;
                    scrap -= upperBorderLength;
                    bNum++;
                }
                else if(aNum<4 || bNum>=2 && aNum<4)
                {
                    scrap = barLength;
                    barNum++;
                    scrap -= borderLength;
                    aNum++;
                }
                else
                {
                    break;
                }
                while (true)
                {
                    int aTmp = scrap - borderLength;
                    int bTmp = scrap - upperBorderLength;
                    if (aTmp>=0&&aTmp<=bTmp&&aNum<4 || aTmp>=0&&aNum<4&&bNum>=2 || bTmp<0 && aNum<4 && aTmp>=0)
                    {
                        scrap = aTmp;
                        aNum++;
                    }
                    else if (bTmp>=0&&bNum<2 || bTmp >= 0 && bNum < 2 && aNum >= 4 || aTmp<0 && bTmp<2 && bTmp>=0)
                    {
                        scrap = bTmp;
                        bNum++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Console.WriteLine(barNum);
        }
    }
}

using System;
using System.Collections.Generic;

namespace CodeForceCs
{
    static class Program
    {
        static void Main(string[] args)
        {
            Solver solver = new _Q910B();
            solver.SolveProblem();
            //Console.ReadKey();
        }
    }

    abstract class Solver
    {
        abstract public void SolveProblem();
    }

    class _Q910B : Solver
    {
        int n, a, b;
        List<int> need = new List<int>();
        override public void SolveProblem()
        {
            n = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            Console.WriteLine(GetResult());
        }

        int GetResult()
        {

            if (n >= 4 * a + 2 * b)
                return 1;

            if (n >= 2 * a + b)
                return 2;

            if (a >= b)
            {
                if (n >= 2 * a)
                    return 3;

                if (n >= a + b)
                    return 4;

                if (n >= 2 * b)
                    return 5;
            }
            else
            {
                if (n >= a + b || n >= 4 * a)
                    return 3;

                if (n >= 2 * a)
                    return 4;
            }
            return 6;
        }
    }

}

using System;
using System.Collections.Generic;

namespace CodeForceCs
{
    static class Program
    {
        static void Main(string[] args)
        {
            Solver solver = new _Q910B();
            solver.SolveProblem();
            //Console.ReadKey();
        }
    }

    abstract class Solver
    {
        abstract public void SolveProblem();
    }

    class _Q910B : Solver
    {
        int n, a, b;
        List<int> need = new List<int>();
        override public void SolveProblem()
        {
            n = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            Console.WriteLine(GetResult());
        }

        int GetResult()
        {

            if (n >= 4 * a + 2 * b)
                return 1;

            if (n >= 2 * a + b)
                return 2;

            if (a >= b)
            {
                if (n >= 2 * a)
                    return 3;

                if (n >= a + b)
                    return 4;

                if (n >= 2 * b)
                    return 5;
            }
            else
            {
                if (n >= a + b)
                    return 3;

                if (n >= 2 * a)
                    return 4;
            }
            return 6;
        }
    }

}

using System;

namespace Обрамление_дверей
{
    class Program
    {
        static void Main(string[] args)
        {
            int barLength = int.Parse(Console.ReadLine());
            int borderLength = int.Parse(Console.ReadLine());
            int upperBorderLength = int.Parse(Console.ReadLine());

            int scrap = barLength, barNum = 1, aNum=0,bNum=0;

            do
            {
                if (scrap >= upperBorderLength && bNum < 2)
                {
                    bNum++;
                    scrap -= upperBorderLength;
                }
                else if (scrap >= borderLength && aNum < 4)
                {
                    aNum++;
                    scrap -= borderLength;
                }
                else
                {
                    scrap = barLength;
                    barNum++;
                }
            }
            while (aNum<4||bNum<2);

            Console.WriteLine(barNum);
        }
    }
}

using System;

namespace Обрамление_дверей
{
    class Program
    {
        static void Main(string[] args)
        {
            int barLength = int.Parse(Console.ReadLine());
            int borderLength = int.Parse(Console.ReadLine());
            int upperBorderLength = int.Parse(Console.ReadLine());

            int scrap, barNum = 0, aNum=0,bNum=0;

            while (true)
            {
                if (upperBorderLength <= borderLength && bNum < 2 || aNum >= 4 && bNum < 2)
                {
                    scrap = barLength;
                    barNum++;
                    scrap -= upperBorderLength;
                    bNum++;
                }
                else if(aNum<4 || bNum>=2 && aNum<4)
                {
                    scrap = barLength;
                    barNum++;
                    scrap -= borderLength;
                    aNum++;
                }
                else
                {
                    break;
                }
                while (true)
                {
                    int aTmp = scrap - borderLength;
                    int bTmp = scrap - upperBorderLength;
                    if (aTmp>=0&&aTmp<=bTmp&&aNum<4 || aTmp>=0&&aNum<4&&bNum>=2)
                    {
                        scrap = aTmp;
                        aNum++;
                    }
                    else if (bTmp>=0&&bNum<2 || bTmp >= 0 && bNum < 2 && aNum >= 4)
                    {
                        scrap = bTmp;
                        bNum++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Console.WriteLine(barNum);
        }
    }
}

using System;

namespace Обрамление_дверей
{
    class Program
    {
        static void Main(string[] args)
        {
            int barLength = int.Parse(Console.ReadLine());
            int borderLength = int.Parse(Console.ReadLine());
            int upperBorderLength = int.Parse(Console.ReadLine());

            int scrap, barNum = 0, aNum=0,bNum=0;

            while (true)
            {
                if (upperBorderLength<=borderLength && bNum<2)
                {
                    scrap = barLength;
                    barNum++;
                    scrap -= upperBorderLength;
                    bNum++;
                }
                else if(aNum<4)
                {
                    scrap = barLength;
                    barNum++;
                    scrap -= borderLength;
                    aNum++;
                }
                else
                {
                    break;
                }
                while (true)
                {
                    int aTmp = scrap - borderLength;
                    int bTmp = scrap - upperBorderLength;
                    if (aTmp>=0&&aTmp<=bTmp&&aNum<4 || aTmp>=0&&aNum<4&&bNum>=2)
                    {
                        scrap = aTmp;
                        aNum++;
                    }
                    else if (bTmp>=0&&bNum<2 || bTmp >= 0 && bNum < 2 && aNum >= 4)
                    {
                        scrap = bTmp;
                        bNum++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Console.WriteLine(barNum);
        }
    }
}

using System;

namespace Обрамление_дверей
{
    class Program
    {
        static void Main(string[] args)
        {
            int barLength = int.Parse(Console.ReadLine());
            int borderLength = int.Parse(Console.ReadLine());
            int upperBorderLength = int.Parse(Console.ReadLine());

            int scrap = barLength, barNum = 1, aNum=0,bNum=0;

            do
            {
                if (scrap>=borderLength&&aNum<4)
                {
                    aNum++;
                    scrap -= borderLength;
                }
                else if (scrap>=upperBorderLength&&bNum<2)
                {
                    bNum++;
                    scrap -= upperBorderLength;
                }
                else
                {
                    scrap = barLength;
                    barNum++;
                }
            }
            while (aNum<4||bNum<2);

            Console.WriteLine(barNum);
        }
    }
}


using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace ConsoleApplication1
{
    class Program
    {
        const int N = 101;
        const int K = 51;
        const int INF = 1000 * 1000 * 1000;
        private static int solve()
        {
            string s = GetString();
            int n = GetInt();
            int[][][] dp1 = new int[101][][];
            for (int i = 0; i < 101; ++i)
            {
                dp1[i] = new int[2][];
                for (int j = 0; j < 2; ++j)
                {
                    dp1[i][j] = new int[51];
                }
            }
            for (int i = 0; i < 101; ++i)
                for (int j = 0; j < 51; ++j)
                {
                    dp1[i][0][j] = dp1[i][1][j] = -INF;
                }
            dp1[0][0][0] = dp1[0][1][0] = 0;
            for (int i = 1; i <= s.Length; ++i)
            {
                for (int j = 0; j <= n; ++j)
                {
                    for (int k = 0; k <= j; ++k)
                    {
                        if (s[i - 1] == 'T')
                        {
                            if (k % 2 == 0)
                            {
                                dp1[i][0][j] = Math.Max(dp1[i - 1][1][j - k], dp1[i][0][j]);
                                dp1[i][1][j] = Math.Max(dp1[i - 1][0][j - k], dp1[i][1][j]);
                            }
                            else
                            {
                                dp1[i][0][j] = Math.Max(dp1[i][0][j], dp1[i - 1][0][j - k] + 1);
                                dp1[i][1][j] = Math.Max(dp1[i][1][j], dp1[i - 1][1][j - k] - 1);
                            }
                        }
                        if (s[i - 1] == 'F')
                        {
                            if (k % 2 == 0)
                            {
                                dp1[i][0][j] = Math.Max(dp1[i][0][j], dp1[i - 1][0][j - k] + 1);
                                dp1[i][1][j] = Math.Max(dp1[i][1][j], dp1[i - 1][1][j - k] - 1);
                            }
                            else
                            {
                                dp1[i][0][j] = Math.Max(dp1[i][0][j], dp1[i - 1][1][j - k]);
                                dp1[i][1][j] = Math.Max(dp1[i][1][j], dp1[i - 1][0][j - k]);
                            }
                        }
                    }
                }
            }
            int ans = Math.Max(dp1[s.Length][0][n], dp1[s.Length ][1][n]);
            return ans;
        }
        public static void Main()
        {
            Console.WriteLine(solve());
        }

        private static  int pos = 0;
        private static string[] st;
        private static string GetString()
        {
            if (st == null || pos == st.Length)
            {
                st = Console.ReadLine().Split(' ');
                pos = 0;
            }
            return st[pos++];
        }
        private static int GetInt()
        {
            return int.Parse(GetString());
        }
        private static double GetDouble()
        {
            return double.Parse(GetString(), CultureInfo.InvariantCulture);
        }
        private static long GetLong()
        {
            return long.Parse(GetString());
        }
    }
}

using System;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Globalization;
using System.Collections.Generic;
using System.Threading;
using System.Linq;

namespace CodeForces
{
	class C
	{
		private const int INF = 1000000;

		private int[, , ,] dp;
		private bool[, , ,] was;
		private string line;

		int go( int p, int done, int n, int left )
		{
			if ( was[p + line.Length, done, n, left] )
				return dp[p + line.Length, done, n, left];
			int res;
			if ( done == line.Length )
			{
				if ( n == 0 )
				{
					res = Math.Abs( p );
				}
				else
				{
					res = -INF;
				}
			}
			else
			{
				if ( line[done] == 'F' )
				{
					res = go( p + ( left == 1 ? -1 : 1 ), done + 1, n, left );
				}
				else
				{
					res = go( p, done + 1, n, 1 - left );
				}
				if ( n > 0 )
				{
					if ( line[done] == 'T' )
					{
						res = Math.Max( res, go( p + ( left == 1 ? -1 : 1 ), done + 1, n - 1, left ) );
					}
					else
					{
						res = Math.Max( res, go( p, done + 1, n - 1, 1 - left ) );
					}
				}
				if ( n > 1 )
				{
					res = Math.Max( res, go( p, done, n - 2, left ) );
				}
			}
			was[p + line.Length, done, n, left] = true;
			return dp[p + line.Length, done, n, left] = res;
		}

		private void Solve()
		{
			line = NextLine();
			var n = NextInt();

			var tc = line.Count( c => c == 'T' );
			if ( tc <= n )
			{
				if ( ( n - tc ) % 2 == 0 )
				{
					Out.WriteLine( line.Length );
				}
				else
				{
					Out.WriteLine( line.Length - 1 );
				}
			}
			else
			{
				was = new bool[2 * line.Length + 1, line.Length + 1, n + 1, 2];
				dp = new int[2 * line.Length + 1, line.Length + 1, n + 1, 2];
				Out.WriteLine( go( 0, 0, n, 0 ) );
			}
		}

		#region Local wireup

		public int NextInt()
		{
			return _in.NextInt();
		}

		public long NextLong()
		{
			return _in.NextLong();
		}

		public string NextLine()
		{
			return _in.NextLine();
		}

		public double NextDouble()
		{
			return _in.NextDouble();
		}

		readonly Scanner _in = new Scanner();
		static readonly TextWriter Out = Console.Out;

		void Start()
		{
#if !ONLINE_JUDGE
			var timer = new Stopwatch();
			timer.Start();
#endif
			var t = new Thread( Solve, 20000000 );
			t.Start();
			t.Join();
#if !ONLINE_JUDGE
			timer.Stop();
			Console.WriteLine( string.Format( CultureInfo.InvariantCulture, "Done in {0} seconds.\nPress <Enter> to exit.", timer.ElapsedMilliseconds / 1000.0 ) );
			Console.ReadLine();
#endif
		}

		static void Main()
		{
			new C().Start();
		}

		class Scanner : IDisposable
		{
			#region Fields

			readonly TextReader _reader;
			readonly int _bufferSize;
			readonly bool _closeReader;
			readonly char[] _buffer;
			int _length, _pos;

			#endregion

			#region .ctors

			public Scanner( TextReader reader, int bufferSize, bool closeReader )
			{
				_reader = reader;
				_bufferSize = bufferSize;
				_closeReader = closeReader;
				_buffer = new char[_bufferSize];
				FillBuffer( false );
			}

			public Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }

			public Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }

#if ONLINE_JUDGE
			public Scanner() : this( Console.In, false ) { }
#else
			public Scanner() : this( "input.txt" ) { }
#endif

			#endregion

			#region IDisposable Members

			public void Dispose()
			{
				if ( _closeReader )
				{
					_reader.Close();
				}
			}

			#endregion

			#region Properties

			public bool Eof
			{
				get
				{
					if ( _pos < _length ) return false;
					FillBuffer( false );
					return _pos >= _length;
				}
			}

			#endregion

			#region Methods

			private char NextChar()
			{
				if ( _pos < _length ) return _buffer[_pos++];
				FillBuffer( true );
				return _buffer[_pos++];
			}

			private char PeekNextChar()
			{
				if ( _pos < _length ) return _buffer[_pos];
				FillBuffer( true );
				return _buffer[_pos];
			}

			private void FillBuffer( bool throwOnEof )
			{
				_length = _reader.Read( _buffer, 0, _bufferSize );
				if ( throwOnEof && Eof )
				{
					throw new IOException( "Can't read beyond the end of file" );
				}
				_pos = 0;
			}

			public int NextInt()
			{
				var neg = false;
				int res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public long NextLong()
			{
				var neg = false;
				long res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public string NextLine()
			{
				SkipUntilNextLine();
				if ( Eof ) return "";
				var builder = new StringBuilder();
				while ( !Eof && !IsEndOfLine( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return builder.ToString();
			}

			public double NextDouble()
			{
				SkipWhitespaces();
				var builder = new StringBuilder();
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return double.Parse( builder.ToString(), CultureInfo.InvariantCulture );
			}

			private void SkipWhitespaces()
			{
				while ( !Eof && IsWhitespace( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private void SkipUntilNextLine()
			{
				while ( !Eof && IsEndOfLine( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private static bool IsWhitespace( char c )
			{
				return c == ' ' || c == '\t' || c == '\n' || c == '\r';
			}

			private static bool IsEndOfLine( char c )
			{
				return c == '\n' || c == '\r';
			}

			#endregion
		}

		#endregion
	}
}

using System;
using System.Collections.Generic;

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

}

class Myon
{
    Scanner cin;
    Myon() { }

    public static void Main()
    {
        new Myon().calc();
    }

    bool[,, ,] dp;
    int n;
    string s;
    int len;
    int ret;

    void calc()
    {
        cin = new Scanner();
        int i, j, k;
        s = Console.ReadLine();
        n = cin.nextInt();
        len = s.Length;
        dp = new bool[101, 300, n + 1, 2];
        ret = 0;
        dfs(0, 150, 0, 0);
        Console.WriteLine(ret);
    }

    void dfs(int now, int pos, int change, int a)
    {
        if (change > n) return;
        if (now == len)
        {
            if (change % 2 != n % 2) return;
            //Console.WriteLine(pos);
            ret = Math.Max(ret, Math.Abs(pos - 150)); return;
        }
        if (dp[now, pos, change, a]) return;
        dp[now, pos, change, a] = true;
        int memo = 1;
        if (s[now] == 'F') memo = 0;
        int v = 1;
        if (a == 1) v = -1;

        dfs(now + 1, pos + v, change + memo, a);
        dfs(now + 1, pos, change + (1 - memo), 1 - a);
    }
}

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

namespace E
{
    class Program
    {
        static string cmd;
        static int?[, , ,] memfr = new int?[101, 51, 220, 2];
        static int?[, , ,] memfl = new int?[101, 51, 220, 2];

        static int farright(int p, int n, int x, bool r)
        {

            if (memfr[p, n, x + 110, r?0:1].HasValue)
                return memfr[p, n, x + 110, r ? 0 : 1].Value;

            char c = cmd[p];
            int ret = 0;
            if (p == cmd.Length - 1)
            {
                if (n % 2 == 1)
                    c = c == 'F' ? 'T' : 'F';
                if (c == 'T')
                    ret = x;
                else if (c == 'F')
                    ret = x + (r ? 1 : -1);
            }
            else
            {
                int v1 = int.MaxValue;
                int v2 = int.MaxValue;
                if (c == 'F' && n > 0)
                {
                    v1 = farright(p + 1, n, x + (r ? 1 : -1), r);
                    v2 = farright(p + 1, n - 1, x, !r);
                }
                else if (c == 'F' && n == 0)
                {
                    v1 = farright(p + 1, n, x + (r ? 1 : -1), r);
                }
                else if (c == 'T' && n > 0)
                {
                    v1 = farright(p + 1, n - 1, x + (r ? 1 : -1), r);
                    v2 = farright(p + 1, n, x, !r);
                }
                else if (c == 'T' && n == 0)
                {
                    v1 = farright(p + 1, n, x, !r);
                }

                ret = v1;
                if (v2 != int.MaxValue)
                    ret = Math.Max(ret, v2);
            }

            memfr[p, n, x + 110, r ? 0 : 1] = ret;
            return ret;
        }

        static int farleft(int p, int n, int x, bool r)
        {
            if (memfl[p, n, x + 110, r ? 0 : 1].HasValue)
                return memfl[p, n, x + 110, r ? 0 : 1].Value;

            char c = cmd[p];
            int ret = 0;
            if (p == cmd.Length - 1)
            {
                if (n % 2 == 1)
                    c = c == 'F' ? 'T' : 'F';
                if (c == 'T')
                    ret = x;
                else if (c == 'F')
                    ret = x + (r ? 1 : -1);
            }
            else
            {
                int v1 = int.MaxValue;
                int v2 = int.MaxValue;
                if (c == 'F' && n > 0)
                {
                    v1 = farright(p + 1, n, x + (r ? 1 : -1), r);
                    v2 = farright(p + 1, n - 1, x, !r);
                }
                else if (c == 'F' && n == 0)
                {
                    v1 = farright(p + 1, n, x + (r ? 1 : -1), r);
                }
                else if (c == 'T' && n > 0)
                {
                    v1 = farright(p + 1, n - 1, x + (r ? 1 : -1), r);
                    v2 = farright(p + 1, n, x, !r);
                }
                else if (c == 'T' && n == 0)
                {
                    v1 = farright(p + 1, n, x, !r);
                }

                ret = v1;
                if (v2 != int.MaxValue)
                    ret = Math.Min(ret, v2);
            }

            memfl[p, n, x + 110, r ? 0 : 1] = ret;
            return ret;
        }

        static void Main(string[] args)
        {
            cmd = Console.ReadLine();
            int n = int.Parse(Console.ReadLine());

            int[] dist = new int[] {
                farright(0, n, 0, true),
                farleft(0, n, 0, true),
                farright(0, n, 0, false),
                farleft(0, n, 0, false)
            };

            Console.WriteLine(dist.Max(x => Math.Abs(x)));
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Logo_Turtle
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();
            int n = int.Parse(reader.ReadLine());

            int sl = s.Length*2;
            var dp = new bool[n + 1,sl + 1,2];
            dp[0, s.Length, 0] = true;

            foreach (char c in s)
            {
                var next = new bool[n + 1,sl + 1,2];

                for (int i = 0; i <= n; i++)
                {
                    for (int j = 0; j <= sl; j++)
                    {
                        if (dp[i, j, 0])
                        {
                            if (c == 'F')
                            {
                                for (int k = i; k <= n; k += 2) next[k, j + 1, 0] = true;
                                for (int k = i + 1; k <= n; k += 2) next[k, j, 1] = true;
                            }
                            else
                            {
                                for (int k = i; k <= n; k += 2) next[k, j, 1] = true;
                                for (int k = i + 1; k <= n; k += 2) next[k, j + 1, 0] = true;
                            }
                        }
                        if (dp[i, j, 1])
                        {
                            if (c == 'F')
                            {
                                for (int k = i; k <= n; k += 2) next[k, j - 1, 1] = true;
                                for (int k = i + 1; k <= n; k += 2) next[k, j, 0] = true;
                            }
                            else
                            {
                                for (int k = i; k <= n; k += 2) next[k, j, 0] = true;
                                for (int k = i + 1; k <= n; k += 2) next[k, j - 1, 1] = true;
                            }
                        }
                    }
                }

                dp = next;
            }

            for (int i = s.Length;; i--)
            {
                if (dp[n, s.Length - i, 0] || dp[n, s.Length - i, 1] || dp[n, s.Length + i, 0] || dp[n, s.Length + i, 1])
                {
                    writer.WriteLine(i);
                    break;
                }
            }

            writer.Flush();
        }
    }
}

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

namespace E
{
    class Program
    {
        static string cmd;
        static int?[, , ,] memfr = new int?[101, 51, 220, 2];
        static int?[, , ,] memfl = new int?[101, 51, 220, 2];

        static int farright(int p, int n, int x, bool r)
        {

            if (memfr[p, n, x + 110, r?0:1].HasValue)
                return memfr[p, n, x + 110, r ? 0 : 1].Value;

            char c = cmd[p];
            int ret = 0;
            if (p == cmd.Length - 1)
            {
                if (n % 2 == 1)
                    c = c == 'F' ? 'T' : 'F';
                if (c == 'T')
                    ret = x;
                else if (c == 'F')
                    ret = x + (r ? 1 : -1);
            }
            else
            {
                int v1 = int.MaxValue;
                int v2 = int.MaxValue;
                if (c == 'F' && n > 0)
                {
                    v1 = farright(p + 1, n, x + (r ? 1 : -1), r);
                    v2 = farright(p + 1, n - 1, x, !r);
                }
                else if (c == 'F' && n == 0)
                {
                    v1 = farright(p + 1, n, x + (r ? 1 : -1), r);
                }
                else if (c == 'T' && n > 0)
                {
                    v1 = farright(p + 1, n - 1, x + (r ? 1 : -1), r);
                    v2 = farright(p + 1, n, x, !r);
                }
                else if (c == 'T' && n == 0)
                {
                    v1 = farright(p + 1, n, x, !r);
                }

                ret = v1;
                if (v2 != int.MaxValue)
                    ret = Math.Max(ret, v2);
            }

            memfr[p, n, x + 110, r ? 0 : 1] = ret;
            return ret;
        }

        static int farleft(int p, int n, int x, bool r)
        {
            if (memfl[p, n, x + 110, r ? 0 : 1].HasValue)
                return memfl[p, n, x + 110, r ? 0 : 1].Value;

            char c = cmd[p];
            int ret = 0;
            if (p == cmd.Length - 1)
            {
                if (n % 2 == 1)
                    c = c == 'F' ? 'T' : 'F';
                if (c == 'T')
                    ret = x;
                else if (c == 'F')
                    ret = x + (r ? 1 : -1);
            }
            else
            {
                int v1 = int.MaxValue;
                int v2 = int.MaxValue;
                if (c == 'F' && n > 0)
                {
                    v1 = farright(p + 1, n, x + (r ? 1 : -1), r);
                    v2 = farright(p + 1, n - 1, x, !r);
                }
                else if (c == 'F' && n == 0)
                {
                    v1 = farright(p + 1, n, x + (r ? 1 : -1), r);
                }
                else if (c == 'T' && n > 0)
                {
                    v1 = farright(p + 1, n - 1, x + (r ? 1 : -1), r);
                    v2 = farright(p + 1, n, x, !r);
                }
                else if (c == 'T' && n == 0)
                {
                    v1 = farright(p + 1, n, x, !r);
                }

                ret = v1;
                if (v2 != int.MaxValue)
                    ret = Math.Min(ret, v2);
            }

            memfl[p, n, x + 110, r ? 0 : 1] = ret;
            return ret;
        }

        static void Main(string[] args)
        {
            cmd = Console.ReadLine();
            int n = int.Parse(Console.ReadLine());

            int xr = farright(0, n, 0, true);
            int xl = farleft(0, n, 0, true);

            //Console.WriteLine(xr);
            Console.WriteLine(Math.Max(Math.Abs(xr), Math.Abs(xl)));
        }
    }
}

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace ConsoleApplication1
{
    class Program
    {
        const int N = 101;
        const int K = 51;
        const int INF = 1000 * 1000 * 1000;
        private static int solve()
        {
            string s = GetString();
            int n = GetInt();
            int[][][] dp1 = new int[101][][];
            int[][][] dp2 = new int[101][][];
            for (int i = 0; i < 101; ++i)
            {
                dp1[i] = new int[2][];
                for (int j = 0; j < 2; ++j)
                {
                    dp1[i][j] = new int[51];
                }
            }
            for (int i = 0; i < 101; ++i)
                for (int j = 0; j < 51; ++j)
                {
                    dp1[i][0][j] = dp1[i][1][j] = -INF;
                }
            for (int k = 0; k <= n; ++k)
                dp1[0][0][k] = dp1[0][1][k] = 0;
            for (int i = 1; i <= s.Length; ++i)
            {
                for (int j = 0; j <= n; ++j)
                {
                    for (int k = 0; k <= j; ++k)
                    {
                        if (s[i - 1] == 'T')
                        {
                            if (k % 2 == 0)
                            {
                                dp1[i][0][j] = Math.Max(dp1[i - 1][1][j - k], dp1[i][0][j]);
                                dp1[i][1][j] = Math.Max(dp1[i - 1][0][j - k], dp1[i][1][j]);
                            }
                            else
                            {
                                dp1[i][0][j] = Math.Max(dp1[i][0][j], dp1[i - 1][0][j - k] + 1);
                                dp1[i][1][j] = Math.Max(dp1[i][1][j], dp1[i - 1][1][j - k] - 1);
                            }
                        }
                        if (s[i - 1] == 'F')
                        {
                            if (k % 2 == 0)
                            {
                                dp1[i][0][j] = Math.Max(dp1[i][0][j], dp1[i - 1][0][j - k] + 1);
                                dp1[i][1][j] = Math.Max(dp1[i][1][j], dp1[i - 1][1][j - k] - 1);
                            }
                            else
                            {
                                dp1[i][0][j] = Math.Max(dp1[i][0][j], dp1[i - 1][1][j - k]);
                                dp1[i][1][j] = Math.Max(dp1[i][1][j], dp1[i - 1][0][j - k]);
                            }
                        }
                    }
                }
            }
            int ans = Math.Max(dp1[s.Length][0][n], dp1[s.Length][1][n]);
            return ans;
        }
        public static void Main()
        {
            Console.WriteLine(solve());
        }

        private static  int pos = 0;
        private static string[] st;
        private static string GetString()
        {
            if (st == null || pos == st.Length)
            {
                st = Console.ReadLine().Split(' ');
                pos = 0;
            }
            return st[pos++];
        }
        private static int GetInt()
        {
            return int.Parse(GetString());
        }
        private static double GetDouble()
        {
            return double.Parse(GetString(), CultureInfo.InvariantCulture);
        }
        private static long GetLong()
        {
            return long.Parse(GetString());
        }
    }
}

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace ConsoleApplication1
{
    class Program
    {
        const int N = 101;
        const int K = 51;
        const int INF = 1000 * 1000 * 1000;
        private static int solve()
        {
            string s = GetString();
            int n = GetInt();
            int[][][] dp1 = new int[101][][];
            int[][][] dp2 = new int[101][][];
            for (int i = 0; i < 101; ++i)
            {
                dp1[i] = new int[2][];
                dp2[i] = new int[2][];
                for (int j = 0; j < 2; ++j)
                {
                    dp1[i][j] = new int[51];
                    dp2[i][j] = new int[51];
                }
            }
            for (int i = 0; i < 101; ++i)
                for (int j = 0; j < 51; ++j)
                {
                    dp1[i][0][j] = dp1[i][1][j] = -INF;
                    dp2[i][0][j] = dp2[i][1][j] = -INF;
                }
            for (int i = 0; i <= n; ++i)
            {
                if (s[0] == 'T')
                {
                    dp1[0][0][i] = i % 2 == 1 ? 1 : -INF;
                    dp1[0][1][i] = i % 2 == 0 ? 0 : -INF;
                    dp2[0][0][i] = i % 2 == 0 ? 0 : -INF;
                    dp2[0][1][i] = i % 2 == 1 ? 1 : -INF;
                }
                else
                {
                    dp1[0][0][i] = i % 2 == 0 ? 1 : -INF;
                    dp1[0][1][i] = i % 2 == 1 ? 0 : -INF;
                    dp2[0][0][i] = i % 2 == 1 ? 0 : -INF;
                    dp2[0][1][i] = i % 2 == 0 ? 1 : -INF;
                }
            }

            for (int i = 1; i < s.Length; ++i)
            {
                for (int j = 0; j <= n; ++j)
                {
                    for (int k = 0; k <= j; ++k)
                    {
                        if (s[i] == 'T')
                        {
                            if (k % 2 == 0)
                            {
                                dp1[i][0][j] = Math.Max(dp1[i - 1][1][j - k], dp1[i][0][j]);
                                dp1[i][1][j] = Math.Max(dp1[i - 1][0][j - k], dp1[i][1][j]);
                                dp2[i][0][j] = Math.Max(dp2[i - 1][1][j - k], dp2[i][0][j]);
                                dp2[i][1][j] = Math.Max(dp2[i - 1][0][j - k], dp2[i][1][j]);
                            }
                            else
                            {
                                dp1[i][0][j] = Math.Max(dp1[i][0][j], dp1[i - 1][0][j - k] + 1);
                                dp1[i][1][j] = Math.Max(dp1[i][1][j], dp1[i - 1][1][j - k] - 1);
                                dp2[i][0][j] = Math.Max(dp2[i][0][j], dp2[i - 1][0][j - k] + 1);
                                dp2[i][1][j] = Math.Max(dp2[i][1][j], dp2[i - 1][1][j - k] - 1);
                            }
                        }
                        if (s[i] == 'F')
                        {
                            if (k % 2 == 0)
                            {
                                dp1[i][0][j] = Math.Max(dp1[i][0][j], dp1[i - 1][0][j - k] + 1);
                                dp1[i][1][j] = Math.Max(dp1[i][1][j], dp1[i - 1][1][j - k] - 1);
                                dp2[i][0][j] = Math.Max(dp2[i][0][j], dp2[i - 1][0][j - k] + 1);
                                dp2[i][1][j] = Math.Max(dp2[i][1][j], dp2[i - 1][1][j - k] - 1);
                            }
                            else
                            {
                                dp1[i][0][j] = Math.Max(dp1[i][0][j], dp1[i - 1][1][j - k]);
                                dp1[i][1][j] = Math.Max(dp1[i][1][j], dp1[i - 1][0][j - k]);
                                dp2[i][0][j] = Math.Max(dp2[i][0][j], dp2[i - 1][1][j - k]);
                                dp2[i][1][j] = Math.Max(dp2[i][1][j], dp2[i - 1][0][j - k]);
                            }
                        }
                    }
                }
            }
            int ans = Math.Max(dp1[s.Length - 1][0][n], dp1[s.Length - 1][1][n]);
            ans = Math.Max(ans, Math.Max(dp2[s.Length - 1][0][n], dp2[s.Length - 1][1][n]));
            return ans;
        }
        public static void Main()
        {
            Console.WriteLine(solve());
        }

        private static  int pos = 0;
        private static string[] st;
        private static string GetString()
        {
            if (st == null || pos == st.Length)
            {
                st = Console.ReadLine().Split(' ');
                pos = 0;
            }
            return st[pos++];
        }
        private static int GetInt()
        {
            return int.Parse(GetString());
        }
        private static double GetDouble()
        {
            return double.Parse(GetString(), CultureInfo.InvariantCulture);
        }
        private static long GetLong()
        {
            return long.Parse(GetString());
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Logo_Turtle
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();
            int n = int.Parse(reader.ReadLine());

            int sl = s.Length*2;
            var dp = new bool[n + 1,sl + 1,2];
            dp[0, s.Length, 0] = true;

            foreach (char c in s)
            {
                var next = new bool[n + 1,sl + 1,2];

                for (int i = 0; i <= n; i++)
                {
                    for (int j = 0; j <= sl; j++)
                    {
                        if (dp[i, j, 0])
                        {
                            if (c == 'F')
                            {
                                next[i, j + 1, 0] = true;
                                if (i + 1 <= n) next[i + 1, j, 1] = true;
                            }
                            else
                            {
                                next[i, j, 1] = true;
                                if (i + 1 <= n) next[i + 1, j + 1, 0] = true;
                            }
                        }
                        if (dp[i, j, 1])
                        {
                            if (c == 'F')
                            {
                                next[i, j - 1, 1] = true;
                                if (i + 1 <= n) next[i + 1, j, 0] = true;
                            }
                            else
                            {
                                next[i, j, 0] = true;
                                if (i + 1 <= n) next[i + 1, j - 1, 1] = true;
                            }
                        }
                    }
                }

                dp = next;
            }

            for (int i = s.Length;; i--)
            {
                if (dp[n, s.Length - i, 0] || dp[n, s.Length - i, 1] || dp[n, s.Length + i, 0] || dp[n, s.Length + i, 1])
                {
                    writer.WriteLine(i);
                    break;
                }
            }

            writer.Flush();
        }
    }
}

using System;
using System.Collections.Generic;

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

}

class Myon
{
    Scanner cin;
    Myon() { }

    public static void Main()
    {
        new Myon().calc();
    }

    bool[,, ,] dp;
    int n;
    string s;
    int len;
    int ret;

    void calc()
    {
        cin = new Scanner();
        int i, j, k;
        s = Console.ReadLine();
        n = cin.nextInt();
        len = s.Length;
        dp = new bool[101, 300, n + 1, 2];
        ret = 0;
        dfs(0, 150, 0, 0);
        Console.WriteLine(ret);
    }

    void dfs(int now, int pos, int change, int a)
    {
        if (change > n) return;
        if (now == len)
        {
            if (change != n) return;
            ret = Math.Max(ret, Math.Abs(pos - 150)); return;
        }
        if (dp[now, pos, change, a]) return;
        dp[now, pos, change, a] = true;
        int memo = 1;
        if (s[now] == 'F') memo = 0;
        int v = 1;
        if (a == 1) v = -1;

        dfs(now + 1, pos + v, change + memo, a);
        dfs(now + 1, pos, change + (1 - memo), 1 - a);
    }
}