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

namespace CodeForces {
    class Pair : IComparable<Pair> {
        public int First, Second,Index;
        public Pair(int f, int s) {
            First = f;
            Second = s;
        }
        public Pair(string s) {
            string[] ss = s.Split(' ');
            First = int.Parse(ss[0]);
            Second = int.Parse(ss[1]);
        }
        public override string ToString() {
            return string.Format("{0} {1}", First, Second);
        }

        public int CompareTo(Pair other) {
            return Math.Abs(other.Second).CompareTo(Math.Abs(Second));
        }
    }

    class Cf {
        static TextReader input;
        static void Main(string[] args) {
#if TESTS
            Stopwatch sw = new Stopwatch();
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Solve();
#if TESTS
            Console.WriteLine();
            Console.WriteLine("Milliseconds: {0}", sw.ElapsedMilliseconds);
            Console.ReadLine();
#endif
        }
        const int MOD = 1000000007;
        static int n, m;
        static string s, t;
        static void Solve() {
            ulong n = ulong.Parse(input.ReadLine());
            if (n == 0)
                Console.WriteLine(1);
            else {
                ulong p1 = binpow(2, n - 1);
                ulong p2 = binpow(2, 2 * n - 1);
                ulong res = (p1 + p2) % MOD;
                Console.WriteLine(res);
            }
        }

        static ulong binpow(ulong a, ulong n) {
            ulong res = 1;
            while (n > 0)
                if ((n & 1)==1) {
                    res = (res * a) % MOD;
                    --n;
                }
                else {
                    a = (a * a) % MOD;
                    n >>= 1;
                }
            return res % MOD;
        }

        static void PrintDouble(double d) {
            Console.WriteLine(d.ToString().Replace(',','.'));
        }

        static int[] Z_function(string s) {
            int n = s.Length;
            int[] z = new int[n];
            for (int i = 1, l = 0, r = 0; i < n; ++i) {
                if (i <= r)
                    z[i] = Math.Min(r - i + 1, z[i - l]);
                while (i + z[i] < n && s[z[i]] == s[i + z[i]])
                    ++z[i];
                if (i + z[i] - 1 > r) {
                    l = i; r = i + z[i] - 1;
                }
            }
            return z;
        }

        static int SquaredDistanceBetweenSegments(int x1, int y1, int x2, int y2, int xx1, int yy1, int xx2, int yy2) {
            return Math.Min(Math.Min(SquaredDistanceToSegment(x1, y1, xx1, yy1, xx2, yy2), SquaredDistanceToSegment(x2, y2, xx1, yy1, xx2, yy2)),
                Math.Min(SquaredDistanceToSegment(xx1, yy1, x1, y1, x2, y2), SquaredDistanceToSegment(xx2, yy2, x1, y1, x2, y2)));
        }

        static int SquaredDistanceToSegment(int x, int y, int x1, int y1, int x2, int y2) {
            int result = Math.Min(SquaredDistance(x, y, x1, y1), SquaredDistance(x, y, x2, y2));
            if (x1 == x2 && y1 <= y && y <= y2)
                result = (x - x1) * (x - x1);
            else if (y1 == y2 && x1 <= x && x <= x2)
                result = (y - y1) * (y - y1);
            return result;
        }

        static int SquaredDistance(int ax, int ay, int bx, int by) {
            return (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
        }

        #region read helpers
        public static List<int> ReadIntList() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        }

        public static int[] ReadIntArray() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static int ReadInt() {
            return int.Parse(input.ReadLine());
        }
#endregion
    }

    public class SegmentTree {
        private int[] a, t;
        private int n;
        public SegmentTree(int[] a) {
            n = a.Length;
            this.a = a;
            t = new int[n << 2];
            buildSegmentTree(0, n - 1, 1);
        }

        private void buildSegmentTree(int l, int r, int v) {
            if (l == r)
                t[v] = a[l];
            else {
                int m = (l + r) >> 1;
                int vl = v << 1;
                int vr = (v << 1) | 1;
                buildSegmentTree(l, m, vl);
                buildSegmentTree(m + 1, r, vr);
                t[v] = t[vl] + t[vr];
            }
        }

        public int QuerySegmentTree(int l, int r) {
            return querySegmentTree(1, l, r, 0, n - 1);
        }

        public void Update(int v, int tl, int tr, int pos, int new_val) {
            if (tl == tr)
                t[v] = new_val;
            else {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                    Update(v << 1, tl, tm, pos, new_val);
                else
                    Update(v << 1 + 1, tm + 1, tr, pos, new_val);
                t[v] = t[v << 1] + t[v << 1 + 1];
            }
        }

        private int querySegmentTree(int v, int l, int r, int tl, int tr) {
            if (l > r)
                return 0;
            if (l == tl && r == tr)
                return t[v];
            int m = (tl + tr) >> 1;
            return querySegmentTree(v << 1, l, Math.Min(r, m), tl, m) + querySegmentTree((v << 1) | 1, Math.Max(l, m + 1), r, m + 1, tr);
        }
    }
    class Graph : List<List<int>> {
        public Graph(int num): base(num) {
            for (int i = 0; i < num; i++) {
                this.Add(new List<int>());
            }
        }
    }
    class Heap<T> : IEnumerable<T> where T : IComparable<T> {
        private List<T> heap = new List<T>();
        private int heapSize;
        private int Parent(int index) {
            return (index - 1) >> 1;
        }
        public int Count {
            get { return heap.Count; }
        }
        private int Left(int index) {
            return (index << 1) | 1;
        }
        private int Right(int index) {
            return (index << 1) + 2;
        }
        private void Max_Heapify(int i) {
            int l = Left(i);
            int r = Right(i);
            int largest = i;
            if (l < heapSize && heap[l].CompareTo(heap[i]) > 0)
                largest = l;
            if (r < heapSize && heap[r].CompareTo(heap[largest]) > 0)
                largest = r;
            if (largest != i) {
                T temp = heap[largest];
                heap[largest] = heap[i];
                heap[i] = temp;
                Max_Heapify(largest);
            }
        }
        private void BuildMaxHeap() {
            for (int i = heap.Count >> 1; i >= 0; --i)
                Max_Heapify(i);
        }

        public IEnumerator<T> GetEnumerator() {
            return heap.GetEnumerator();
        }

        public void Sort() {
            for (int i = heap.Count - 1; i > 0; --i) {
                T temp = heap[i];
                heap[i] = heap[0];
                heap[0] = temp;
                --heapSize;
                Max_Heapify(0);
            }
        }

        public T Heap_Extract_Max() {
            T max = heap[0];
            heap[0] = heap[--heapSize];
            Max_Heapify(0);
            return max;
        }

        public void Clear() {
            heap.Clear();
            heapSize = 0;
        }

        public void Insert(T item) {
            if (heapSize < heap.Count)
                heap[heapSize] = item;
            else
                heap.Add(item);
            int i = heapSize;
            while (i > 0 && heap[Parent(i)].CompareTo(heap[i]) < 0) {
                T temp = heap[i];
                heap[i] = heap[Parent(i)];
                heap[Parent(i)] = temp;
                i = Parent(i);
            }
            ++heapSize;
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)heap).GetEnumerator();
        }
    }
    public class Treap {
        private static Random rand = new Random();
        public static Treap Merge(Treap l, Treap r) {
            if (l == null) return r;
            if (r == null) return l;
            Treap res;
            if (l.y > r.y) {
                Treap newR = Merge(l.right, r);
                res = new Treap(l.x, l.y, l.left, newR);
            }
            else {
                Treap newL = Merge(l, r.left);
                res = new Treap(r.x, r.y, newL, r.right);
            }
            return res;
        }

        public void Split(int x, out Treap l, out Treap r) {
            Treap newTree = null;
            if (this.x <= x) {
                if (right == null)
                    r = null;
                else
                    right.Split(x, out newTree, out r);
                l = new Treap(this.x, y, left, newTree);
            }
            else {
                if (left == null)
                    l = null;
                else
                    left.Split(x, out l, out newTree);
                r = new Treap(this.x, y, newTree, right);
            }
        }

        public Treap Add(int x) {
            Treap l, r;
            Split(x, out l, out r);
            Treap m = new Treap(x, rand.Next());
            return Merge(Merge(l, m), r);
        }

        public Treap Remove(int x) {
            Treap l, m, r;
            Split(x - 1, out l, out r);
            r.Split(x, out m, out r);
            return Merge(l, r);
        }

        private int x, y, cost, maxTreeCost;
        private Treap left, right;
        public Treap(int x, int y, Treap l, Treap r) {
            this.x = x;
            this.y = y;
            left = l;
            right = r;
        }
        public Treap(int x, int y) : this(x, y, null, null) { }
        public void InOrder() {
            inOrder(this);
        }
        private void inOrder(Treap t) {
            if (t == null) return;
            inOrder(t.left);
            Console.WriteLine(t.x);
            inOrder(t.right);
        }
    }
    public static class Extensions {
        public static void Fill(this int[] array, int val) {
            for (int i = 0; i < array.Length; i++) {
                array[i] = val;
            }
        }

        public static void Fill(this double[] array, double val) {
            for (int i = 0; i < array.Length; i++) {
                array[i] = val;
            }
        }

        public static int ToInt(this string s) {
            return int.Parse(s);
        }

        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static void Print<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}


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

namespace C
{
    class Program
    {
        static long bin_pow(long a, long n, long d)
        {
            long res = 1;
            for (long t = a; n>0; t=(t*t)%d)
            {
                if (n%2==1)
                {
                    res = (res * t) % d;
                }
                n /= 2;
            }
            return res;
        }
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long d = 1000000007;
            long t = bin_pow(2, n, d);
            long res = ((1 + t) * t / 2) % d;
            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}


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

namespace Sharp
{

    class Program {
        private static Reader cin;
        private static TextWriter cout;
        private static long MOD = 998244353;
        private static long[] f;
        static long solve(int a, int b) {
            f = new long[b + 1];
            f[b] = 1;
            for (int i = 0; i < a; ++i) {
                for (int j = 0; j < b; ++j) {
                    f[j] = (f[j] + f[j + 1] * (j + 1)) % MOD;
                }
            }

            long ans = 0;
            for (int i = 0; i <= b; ++i) {
                ans = (ans + f[i]) % MOD;
            }

            return ans;
        }
        static void Main(string[] args) {
            cin = new Reader(Console.In);
            cout = Console.Out;
            int a, b, c;
            cin.Read(out a).Read(out b).Read(out c);
            long ans = 1;
            ans = (ans * solve(a, b)) % MOD;
            ans = (ans * solve(a, c)) % MOD;
            ans = (ans * solve(c, b)) % MOD;
            cout.WriteLine(ans);

        }
    }

    class Reader
    {
        TextReader TextRdr;

        String[] Buffer;
        int Id;
        public Reader(TextReader reader) {
            TextRdr = reader;
            Id = 0;
        }

        public String ReadLine() {
            return TextRdr.ReadLine();
        }

        public String Next() {
            if ((Buffer == null) || (Id == Buffer.Length)) {
                Buffer = ReadLine().Split();
                Id = 0;
            }
            return Buffer[Id++];
        }

        public Reader Read<T>(out T what) {
            what = (T)Convert.ChangeType(Next(), typeof(T));
            return this;
        }

        public T Read<T>() {
            return (T)Convert.ChangeType(Next(), typeof(T));
        }

    }

    class Pair<T1, T2>
    {
        public Pair() {
        }

        public Pair(T1 first, T2 second) {
            this.First = first;
            this.Second = second;
        }

        public T1 First { get; set; }
        public T2 Second { get; set; }
    };

}


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

namespace CF
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
//			using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
                //using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        const long mod = 998244353L;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var a = sr.NextInt32();
            var b = sr.NextInt32();
            var c = sr.NextInt32();
            var facts = Facts(Math.Max(a, Math.Max(b, c)));
            var coeffs = BinCoeff(Math.Max(a, Math.Max(b, c)));
            sw.WriteLine(((Func(a, b, facts, coeffs)*Func(b, c, facts, coeffs)%mod)*Func(c, a, facts, coeffs))%mod);
        }

        private long[] Facts(int max)
        {
            var facts = new long[max + 1];
            facts[0] = 1L;
            for (var i = 1; i <= max; i++) {
                facts[i] = (facts[i - 1] * i) % mod;
            }

            return facts;
        }

        private long Func(long a, long b, long[] facts, long[,] binCoeff)
        {
            var max = Math.Max(a, b);
            var r = 0L;
            for (var i = 0; i <= max; i++) {
                r = (r + binCoeff[a, i] * binCoeff[b, i]%mod * facts[i] % mod) % mod;
            }

            return r;
        }

        private long[,] BinCoeff(int max)
        {
            var coeff = new long[max + 1, max + 1];
            for (var i = 0; i <= max; i++) {
                coeff[i, 0] = 1;
                coeff[i, i] = 1;
            }
            for (var i = 1; i <= max; i++) {
                for (var j = 1; j <= i; j++) {
                    coeff[i, j] = (coeff[i - 1, j] + coeff[i - 1, j - 1])%mod;
                }
            }

            return coeff;
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += (long)Intersectie(x1, x2, L[i - 1] + 1, L[i]) * (long)Intersectie(y1, y2, L[j], L[j + 1] - 1);
            Rez += (long)Intersectie(y1, y2, L[i - 1] + 1, L[i]) * (long)Intersectie(x1, x2, L[j], L[j + 1] - 1);
            if (k == 1 && x1 <= L[i] && L[i] <= x2 && y1 <= L[i] && L[i] <= y2) Rez--;
        }

        long Posibilitati = (long)(x2 - x1 + 1) * (long)(y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static long Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drA <= drB) return drA - stB + 1;
        if (stB <= stA && drB <= drA) return drB - stA + 1;
        return 0;
    }
}


using System;
using System.IO;
//using System.Reflection;
//using System.Collections;
using System.Collections.Generic;
using System.Linq;
//using System.Text;
//using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static class Scanner
        {
            readonly static IEnumerator<string> Tokens;
            static Scanner()
            {
                Tokens = Enumerable.Range(Int32.MinValue, Int32.MaxValue).
                    Select(s => Console.ReadLine()).
                    TakeWhile(s => s != null).
                    SelectMany(s => s.Split(new[] { ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries)).
                    Concat(Enumerable.Repeat(0, 1).Select(_ => (string)null)).
                    GetEnumerator();
            }

            public static string NextToken()
            {
                Tokens.MoveNext();
                return Tokens.Current;
            }
        }

        int nextInt()
        {
            return int.Parse(Scanner.NextToken());
        }

        bool GoodValue(int a)
        {
            if (a <= 0) return false;
            while (a != 0)
            {
                if (a % 10 != 7 && a % 10 != 4) return false;
                a /= 10;
            }
            return true;
        }

        int[] GenSequence()
        {
            var l = new List<int>();
            var q = new Queue<int>();
            q.Enqueue(0);
            while (q.Count != 0)
            {
                int cur = q.Dequeue();
                l.Add(cur);
                if (GoodValue(cur * 10 + 4)) q.Enqueue(cur * 10 + 4);
                if (GoodValue(cur * 10 + 7)) q.Enqueue(cur * 10 + 7);
            }
            return l.Concat(Enumerable.Range(1111111111, 1)).OrderBy(c => c).ToArray();
        }

        int LowerBound(int v, int[] a)
        {
            int x = 0, y = a.Length;
            while (y - x > 1)
            {
                int z = (x + y) / 2;
                if (a[z] <= v) x = z;
                else y = z;
            }
            return x;
        }

        int Len(int x, int y, int[] a, int p)
        {
            if (p < 1 || p >= a.Length) return 0;
            int tx = Math.Max(x, a[p - 1]), ty = Math.Min(y, a[p]);
            if (GoodValue(tx)) tx++;
            if (GoodValue(ty)) ty--;
            return Math.Max(ty - tx + 1, 0);
        }

        void Solve()
        {
            var values = GenSequence();
            int pl = nextInt(), pr = nextInt(),
                vl = nextInt(), vr = nextInt(),
                k = nextInt();
            long res = 0;
            for (int x = 1; x < values.Length; x++)
            {
                long pc = Len(pl, pr, values, x);
                long rc1 = Len(vl, vr, values, x + k),
                    rc2 = Len(vl, vr, values, x - k);
                res += pc * (rc1 + rc2);
                if (x + k - 1 < values.Length && values[x + k - 1] >= vl && values[x + k - 1] <= vr) res += pc;
                if (x - k > 0 && values[x - k] >= vl && values[x - k] <= vr) res += pc;

                if (values[x] >= pl && values[x] <= pr)
                {
                    res += Len(vl, vr, values, x - k + 1);
                    res += Len(vl, vr, values, x + k);

                    res += new[] { x + k - 1, x - k + 1 }.Distinct().Where(
                        c => c > 0 && c < values.Length &&
                            values[c] >= vl && values[c] <= vr
                        ).Count();
                }
            }
            long all = (pr - pl + 1);
            all *= (vr - vl + 1);
            Console.Write("{0:F12}", (double)res / (double)(all));
        }

        static void Main()
        {
#if MY_SUPER_PUPER_ONLINE_JUDGE
            string dir = Directory.GetCurrentDirectory();
            dir = Directory.GetParent(dir).FullName;
            dir = Directory.GetParent(dir).FullName;
            Console.SetIn(new StreamReader(dir + "\\input.txt"));
            Console.SetOut(new StreamWriter(dir + "\\output.txt"));
#endif
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            new Program().Solve();
#if MY_SUPER_PUPER_ONLINE_JUDGE
            Console.In.Close();
            Console.Out.Close();
#endif
        }
    }
}


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
{
    public void Solve()
    {
        long n = ReadLong() - 1;
        int l = 0, r = 1000000000;
        while (l < r)
        {
            int mid = (l + r) / 2;
            if (3L * mid * (mid + 1) <= n)
                l = mid + 1;
            else
                r = mid;
        }

        long x = l * 2 - 1;
        long y = 2;
        if (l > 1)
            n -= 3L * l * (l - 1);

        long v = Math.Min(n, l - 1);
        x -= v;
        y += v * 2;
        n -= v;

        v = Math.Min(n, l);
        x -= v * 2;
        n -= v;

        v = Math.Min(n, l);
        x -= v;
        y -= v * 2;
        n -= v;

        v = Math.Min(n, l);
        x += v;
        y -= v * 2;
        n -= v;

        v = Math.Min(n, l);
        x += v * 2;
        n -= v;

        v = Math.Min(n, l);
        x += v;
        y += v * 2;

        Write(x, y);
    }

    #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
        {
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#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;
class E
{
	static void Main()
	{
		var N = long.Parse(Console.ReadLine());
		if (N == 0) { Console.WriteLine("0 0"); return; }
		var k = FirstBinary(0, Math.Min(600000000, N), t => 3 * (t + 1) * (t + 2) >= N) + 1;
		var x = 2 * k;
		var y = 0L;
		var dx = new long[] { -1, -2, -1, 1, 2, 1 };
		var dy = new long[] { 2, 0, -2, -2, 0, 2 };
		N -= 3 * k * (k - 1) + 1;
		if (N < 0) N += 6 * k;
		for (var i = 0; i < 6; i++)
		{
			if (N < k)
			{
				N++;
				x += N * dx[i];
				y += N * dy[i];
				Console.WriteLine("{0} {1}", x, y);
				break;
			}
			N -= k;
			x += k * dx[i];
			y += k * dy[i];
		}
	}
	public static long FirstBinary(long min, long max, Predicate<long> pred)
	{
		var left = min;
		var right = max;
		while (left < right)
		{
			var mid = (left + right) >> 1;
			if (pred(mid)) right = mid;
			else left = mid + 1;
		}
		return left;
	}
}


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

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                var m = ReadLong();
                var res = Recurse(m);
                return res.Item1 + " " + res.Item2;
            }
        }

        Tuple<long, long> Recurse(long m)
        {
            if (m < 8)
                return Tuple.Create(m, m);
            var root = MaxRoot(m);
            var cube = root * root * root;
            var lesserCube = (root - 1) * (root - 1) * (root - 1);
            var firstAns = Recurse(m - cube);
            var secondAns = Recurse(cube - 1 - lesserCube);
            return firstAns.Item1 >= secondAns.Item1
                ? Tuple.Create(firstAns.Item1 + 1, cube + firstAns.Item2)
                : Tuple.Create(secondAns.Item1 + 1, lesserCube + secondAns.Item2);

        }

        long MaxRoot(long x)
        {
            var root = (long) Math.Floor(Math.Pow(x, 1d / 3));
            if ((root + 1) * (root + 1) * (root + 1) <= x)
                root++;
            return root;
        }

        int Solve(string s1, string s2, int L, int m)
        {
            var diff = s1.Length + s2.Length - L;
            if (diff > 0)
            {
                if (s1.Substring(s1.Length - diff) == s2.Substring(0, diff))
                    return 1 % m;
                else
                    return 0;
            }
            else
            {
                return FastPow(26, Math.Abs(diff), m);
            }
        }

        public int FastPow(int b, int pow, int mod)
        {
            if (pow == 0)
                return 1 % mod;
            if (pow == 1)
                return b % mod;
            if ((pow & 1) == 0)
                return FastPow(b * b % mod, pow / 2, mod);
            return b * FastPow(b, pow - 1, mod) % mod;
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}


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

namespace AlgoTraining.Codeforces.D_s
{
    public class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public int NextInt()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt32(_line[_iterator++]);
        }
        public long NextLong()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt64(_line[_iterator++]);
        }
    }
    class BearAndTowerOfCubes356
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                long m = fs.NextLong(), d = 0;
                long count = Solve(m, ref d);
                writer.WriteLine(count + " " + (m - d));
            }
        }
        public static long Solve(long m, ref long d)
        {
            if (m < 8) return m;
            long r2 = (long)Math.Pow((long)Math.Pow(m, 1.0 / 3.0), 3);
            long r1 = (long)Math.Pow((long)Math.Pow(m, 1.0 / 3.0) - 1, 3);
            long p2 = m - r2;
            long p1 = r2 - 1 - r1;

            long d1 = 0, d2 = 0;
            long a1 = 1 + Solve(p1, ref d1);
            long a2 = 1 + Solve(p2, ref d2);

            if (a2 >= a1)
            {
                d += d2;
                return a2;
            }
            else
            {
                d += m - r2 + 1;
                d += d1;
                return a1;
            }
        }
    }
}


using System;
using Math = System.Math;
using Dec = System.Decimal;
using System.Globalization;
using System.Linq;

namespace taskA
{
	class newDecimal {
	private
			Int64 Z, F, kol;
	public newDecimal(decimal t, Int64 Kol) {
			kol = Kol;
			Z = Dec.ToInt64 (t);
			Int64 p = 1;
			for (int i = 0; i < kol; i ++)
				p *= 10L;
			F = Dec.ToInt64 ((t - Z) * p);
		}
		public void print () {
			Console.Write ("{0}.", Z);
			int sz = F.ToString ().Length;
			for (int i = 0; i < kol - sz; i ++)
				Console.Write (0);
			Console.Write (F);
		}
	}

	class MainClass
	{
		public static long[,] C = new long[800, 10];

		public static void PreCalc() {
			C [1,1] = 1L;
			C [2,1] = 2L;
			C [2,2] = 1L;
			for (int i = 3; i <= 777; i ++) C[i,1] = 1L*i;
			for (int i = 3; i <= 777; i ++)
				for (int j = 2; j <= 7; j ++)
					C [i,j] = C [i - 1,j] + C [i - 1,j - 1];
		}

		public static void Main(string[] args) {
			long n = long.Parse (Console.ReadLine ());
			int[] a = {2, 3, 5, 7};
			long ans = n;
			for (int i = 0; i < 4; i ++) ans -= n / a[i];
			for (int i = 0; i < 4; i ++)
				for (int j = i + 1; j < 4; j ++)
					ans += n / a[i] / a[j];
			for (int i = 0; i < 4; i ++)
				for (int j = i + 1; j < 4; j ++)
					for (int k = j + 1; k < 4; k ++)
						ans -= n / a[i] / a[j] / a[k];
			ans += n / 2 / 3/ 5/ 7;
			Console.WriteLine(ans);
		}
	}
}


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

namespace ChallengePennants
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            long n = long.Parse(s);
            if (n <= 10)
            {
                Console.WriteLine(1);
            }
            else
            {
                long x = n / 2 + n / 3 + n / 5 + n / 7;
                x -= n / 6 + n / 10 + n / 14 + n / 15 + n / 21 + n / 35;
                x += n / 30 + n / 42 + n / 70 + n / 105;
                x -= n / 210;
                Console.WriteLine("{0:d}", n - x);
            }
        }
    }
}


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

class cf740
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static void Main()
    {
        var c = NList;
        var (n, key) = (c[0], c[1]);
        var suball = 0L;
        var dp = new long[n + 1];
        dp[n] = 1;
        for (var i = n; i > 1; --i)
        {
            var val = (dp[i] + suball) % key;
            suball = (suball + val) % key;
            var last = i;
            for (var j = 2; j * j <= i; ++j)
            {
                dp[i / j] = (dp[i / j] + val) % key;
                last = i / j;
            }
            var sub = 0;
            for (var j = 1; j < last; ++j)
            {
                var mul = i - i / (j + 1) - sub;
                dp[j] = (dp[j] + val * mul) % key;
                sub += mul;
            }
        }
        WriteLine((dp[1] + suball) % key);
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solution
{
    public void Solve()
    {
        int n = ReadInt();
        int mod = ReadInt();

        var dp = new long[n + 1];
        dp[1] = 1;
        long sum = 1;
        for (int i = 2; i <= n; i++)
        {
            dp[i] = sum;
            int j;
            for (j = 2; j * j <= i; j++)
                dp[i] = (dp[i] + dp[i / j]) % mod;
            int p = j - 1;
            for (j = i / j; j > 0; j--)
            {
                int o = i / j;
                dp[i] = (dp[i] + (o - p) * dp[j]) % mod;
                p = o;
            }
            sum = (sum + dp[i]) % mod;
        }

        Write(dp[n]);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUGLOCAL
        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("ysys.in");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solution().Solve();
            //var thread = new Thread(new Solution().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUGLOCAL
            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.Diagnostics;
using System.IO;
using System.Linq;
using static System.Console;

namespace CodeForces
{
    public class Program
    {
        static void Main()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            Solve(In, Out);
            PrintTime(stopwatch);
        }
        public static void Solve(TextReader In, TextWriter Out)
        {
            int[] input = In.ReadLine().Split().Select(str => int.Parse(str)).ToArray();
            int N = input[0], m = input[1];

            int[] f = new int[N * 2 + 1];
            f[N] = 1;
            for (long n = N - 1; n > 0; n--)
            {
                f[n] = 2 * f[n + 1] % m;
                for (int i = 2; i <= N / n; i++)
                {
                    f[n] = (f[n] + f[i * n] - f[(n + 1) * i]) % m;
                    if (f[n] < 0)
                    {
                        f[n] += m;
                    }
                }
            }
            int res = (f[1] - f[2]) % m;
            if (res < 0)
            {
                res += m;
            }

            Out.WriteLine(res);
        }

        [Conditional("DEBUG")]
        internal static void PrintTime(Stopwatch stopwatch) => WriteLine(stopwatch.Elapsed);
    }
}


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

class PairVariable : IComparable<PairVariable>
{
    public decimal a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = decimal.Parse(q[0]);
        b = decimal.Parse(q[1]);
    }
    public PairVariable(decimal a, decimal b)
    {
        this.a = a;
        this.b = b;
    }

    public int CompareTo(PairVariable other)
    {
        return this.a.CompareTo(other.a);
    }
}

namespace ConsoleApplication254
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            bool[] p = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                if (!p[i])
                {
                    for (int e = i + i; e <= n; e+=i)
                    {
                        p[e] = true;
                    }
                }
            }
            int k = 0;
            for (int i = 0; i < p.Length; i++)
            {
                if (!p[i])
                {
                    k++;
                }
            }
            int[] arr = new int[k];
            k = 0;
            for (int i = 2; i < p.Length; i++)
            {
                if (!p[i])
                {
                    arr[k] = i;
                    k++;
                }
            }
            List<int> r = new List<int>();
            while (n != 1)
            {

                int t = 0;
                for (int i = 0; i < arr.Length; i++)
                {
                    if (n % arr[i] == 0)
                    {
                        t = arr[i];
                        break;
                    }
                }
                r.Add(t);
                n /= t;
            }
            /*for (int i = 0; i < r.Count; i++)
            {
                Console.WriteLine(r[i]);
            }*/
            if (m > r.Count)
            {
                Console.WriteLine(-1);

            }
            else
            {
              //  Console.WriteLine(r.Count);
                int ans = 1;
                for (int i = 0; i < m-1; i++)
                {
                    Console.Write(r[i]+" ");
                }
                for (int i = m-1; i < r.Count; i++)
                {
                    ans *= r[i];
                }
                Console.WriteLine(ans);
            }

        }
    }
}


using System;

namespace CF3
{
    class Program
    {
        public static int SmallDiv(int n)
        {
            int div = 1;
            for (int i = 2; i <= n/2; i++)
                if (n % i == 0)
                {
                    div = i;
                    break;
                }

            return (div == 1) ? n : div;
        }

        static void Main(string[] args)
        {
            string[] a = Console.ReadLine().Split(' ');
            int n = int.Parse(a[0]);
            int k = int.Parse(a[1]);
            string s = "";
            int div;

            for (int i = 0; i < k; i++)
            {
                div = SmallDiv(n);
                if(i < k - 1 && div == n)
                {
                    s = "-1";
                    break;
                }
                s += (i != k - 1) ? div : n;
                s += " ";
                n /= div;
            }
            Console.WriteLine(s);
        }
    }
}


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;

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;
using System.Text.RegularExpressions;

namespace D07_10_12
{
    class Program
    {
        static void Main()
        {
            string[] s = Regex.Split(Console.ReadLine(), " ");
            int vx = int.Parse(s[0]);
            int vy = int.Parse(s[1]);
            int vz = int.Parse(s[2]);
            s = Regex.Split(Console.ReadLine(), " ");
            int px = int.Parse(s[0]);
            int py = int.Parse(s[1]);
            int pz = int.Parse(s[2]);
            s = Regex.Split(Console.ReadLine(), " ");
            int n = int.Parse(s[0]);
            int v = int.Parse(s[1]);
            int d = int.Parse(s[2]);
            int b = int.Parse(s[3]);
            int l = int.Parse(s[4]);
            int p = int.Parse(s[5]);
            int sum = 0;
            if (vx > px) sum += p;
            if (vx < 0) sum += l;
            if (vy > py) sum += v;
            if (vy < 0) sum += n;
            if (vz > pz) sum += b;
            if (vz < 0) sum += d;
            Console.WriteLine("{0}", sum);

        }
    }
}


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

namespace CodeForces
{
    class R143_Div2_D
    {
        static void Main(string[] args)
        {
            string[] s = (Console.ReadLine().Split());
            int x = Convert.ToInt32(s[0]);
            int y = Convert.ToInt32(s[1]);
            int z = Convert.ToInt32(s[2]);

            s = (Console.ReadLine().Split());
            int x1 = Convert.ToInt32(s[0]);
            int y1 = Convert.ToInt32(s[1]);
            int z1 = Convert.ToInt32(s[2]);

            s = (Console.ReadLine().Split());
            int[] a = new int[7];
            for (int i = 1; i <= 6; i++)
            {
                a[i] = Convert.ToInt32(s[i-1]);
            }

            int cnt = 0;
            if (y < 0)
                cnt += a[1];
            if (y > y1)
                cnt += a[2];

            if (z < 0)
                cnt += a[3];
            if (z > z1)
                cnt += a[4];

            if (x < 0)
                cnt += a[5];
            if (x > x1)
                cnt += a[6];

            Console.WriteLine(cnt);
        }
    }
}


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

namespace CodeForces
{
    class R183_Div2_D
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int x = int.Parse(s[2]);
            int y = int.Parse(s[3]);
            int a = int.Parse(s[4]);
            int b = int.Parse(s[5]);
            int g = GCD_Euclid(a, b);
            a = a / g;
            b = b / g;

            int xDif = Math.Min(n - x, x - 0);
            int yDif = Math.Min(m - y, y - 0);

            int t = Math.Min(n / a, m / b);
            a *= t;
            b *= t;

            int x1, y1, x2, y2;
            x1 = x - a + (a / 2);
            y1 = y - b + (b / 2);
            x1 = Math.Min(x1, n - a);
            y1 = Math.Min(y1, m - b);
            x1 = Math.Max(x1, 0);
            y1 = Math.Max(y1, 0);
            x2 = x1 + a;
            y2 = y1 + b;
            Console.WriteLine(x1 + " " + y1 + " " + x2 + " " + y2);
        }

        static int GCD_Euclid(int a, int b)
        {
            if (b == 0) return a;
            return GCD_Euclid(b, a % b);
        }
    }
}


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

namespace Codeforces
{
    class Program {

        #region input

        static long readLong() {
            long num;
            long.TryParse(Console.ReadLine(),out num);
            return num;
        }

        static ulong readULong() {
            ulong num;
            ulong.TryParse(Console.ReadLine(),out num);
            return num;
        }

        static int readInt() {
            int num;
            int.TryParse(Console.ReadLine(),out num);
            return num;
        }

        static bool readBool() {
            int num;
            int.TryParse(Console.ReadLine(),out num);
            return num != 0;
        }

        static long[] readLongs() {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            long[] parsed = new long[nums.Length];
            for(int i = 0; i < nums.Length; i++) {
                long.TryParse(nums[i],out parsed[i]);
            }
            return parsed;
        }

        static int[] readInts() {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            int[] parsed = new int[nums.Length];
            for(int i = 0; i < nums.Length; i++) {
                int.TryParse(nums[i],out parsed[i]);
            }
            return parsed;
        }

        static void readInts(out int a, out  int b) {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            int[] parsed = new int[nums.Length];
            int.TryParse(nums[0],out a);
            int.TryParse(nums[1],out b);
        }

        static BitArray readBools() {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            BitArray bits = new BitArray(nums.Length);
            for(int i = 0; i < nums.Length; i++) {
                if(nums[i] != "0") {
                    bits[i] = true;
                }
            }
            return bits;
        }

        static BitArray readBools(string off) {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            BitArray bits = new BitArray(nums.Length);
            for(int i = 0; i < nums.Length; i++) {
                if(nums[i] != off) {
                    bits[i] = true;
                }
            }
            return bits;
        }

        static void waist() {
            Console.ReadLine();
        }

        #endregion

        #region utility

        static long largeModolu(long a,long b,long m) {
            long prev = a;
            long sum = (b & 1) > 0 ? a : 1;
            int digits = (int)(Math.Ceiling(Math.Log(b,2)));
            for(int i = 1; i < digits; i++) {
                prev = (prev * prev) % (m);
                if((b & (1l << i)) > 0) {
                    sum = (sum * prev) % (m);
                }
            }
            return sum;
        }

        static long GCD(long a, long b) {
            long temp;
            if(a > b) {
                temp = b;
                b = a;
                a = temp;
            }
            while(b != 0) {
                temp = b;
                b = a % b;
                a = temp;
            }
            return a;
        }

        class SortableKVP<T> where T : IComparable {
            List<Tuple<int,T>> data { set; get; }

            public int count {
                get {
                    return data.Count;
                }
            }

            public T this[int index] {
                get {
                    return data[index].Item2;
                }
            }

            public int originalIndex(int sortedIndex) {
                return data[sortedIndex].Item1;
            }

            public void sort() {
                data.Sort((a,b) => a.Item2.CompareTo(b.Item2));
            }

            public void add(T item) {
                data.Add(new Tuple<int,T>(data.Count,item));
            }

            public void removeAt(int sortedIndex) {
                data.RemoveAt(sortedIndex);
            }

            public SortableKVP() {
                data = new List<Tuple<int,T>>();
            }

            public SortableKVP(T[] data) {
                this.data = new List<Tuple<int,T>>(data.Length);
                for(int i = 0; i < data.Length; i++) {
                    this.data.Add(new Tuple<int,T>(i,data[i]));
                }
            }
        }

        #endregion

        static void Main(string[] args) {
            long[] nmxyab = readLongs();
            long n = nmxyab[0];
            long m = nmxyab[1];
            long x = nmxyab[2];
            long y = nmxyab[3];
            long a = nmxyab[4];
            long b = nmxyab[5];
            long gcd = GCD(a,b);
            a /= gcd;
            b /= gcd;
            long multiplier = Math.Min(n / a,m / b);
            long xLength = a * multiplier;
            long yLength = b * multiplier;
            long x1 = Math.Min(n - xLength,Math.Max(0,x - (xLength + 1) / 2));
            long y1 = Math.Min(m - yLength,Math.Max(0,y - (yLength + 1) / 2));
            Console.WriteLine(x1 + " " + y1 + " " + (x1 + xLength) + " " + (y1 + yLength));
        }

        /*static void Main(string[] args) {
            BitArray primes = new BitArray(1000001,true);
            primes[0] = false;
            primes[1] = false;
            for(int i = 2; i * i <= 1000000; i++) {
                if(primes[i]) {
                    for(int j = i * 2; j <= 1000000; j += i) {
                        primes[j] = false;
                    }
                }
            }
            int t = readInt();
            for(int r = 0; r < t; r++) {
                int[] range = readInts();
                int sum = 0;
                for(int i = range[0]; i <= range[1]; i++) {
                    if(primes[i]) {
                        sum++;
                    }
                }
                Console.WriteLine(sum);
            }
            Console.Read();
        }*/

        /*static void Main(string[] args) {
            int t = readInt();
            for(int r = 0; r < t; r++) {
                waist();
                int[] nums = readInts();
                Array.Sort(nums, (a,b) => b.CompareTo(a));
                for(int i = 0; i < nums.Length; i++) {
                    if((i & 1) == 0 ) {
                        Console.Write(nums[i/2]);
                    } else {
                        Console.Write(nums[nums.Length - 1- (i-1)/2]);
                    }
                    if(i == nums.Length - 1) {
                        Console.WriteLine("");
                    } else {
                        Console.Write(" ");
                    }
                }
            }
            Console.Read();
        }*/
    }
}
//0.89493155168539774035319
//0.894931551685397740353194
//0.894931551685397735434921


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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] Inp = Console.ReadLine().Split();
            int N = Convert.ToInt32(Inp[0]), K = Convert.ToInt32(Inp[1]);

            int Min = Int32.MaxValue;
            for (int i = 1; i < K; i++)
            {
                if (N % i == 0)
                {
                    int X = (N / i) * K + i;
                    if ((X / K) * (X % K) == N)
                        Min = Math.Min(Min, X);
                }
            }

            Console.WriteLine(Min);
        }
    }
}


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

namespace CodeForces
{
    public class CodeForces
    {
        static void Main(string[] args)
        {
            var Inp = Console.ReadLine().Split();
            int n = Convert.ToInt32(Inp[0]);
            int k = Convert.ToInt32(Inp[1]);

            int min = Int32.MaxValue;
            for (int i = 1; i < k; i++)
            {
                if (n % i == 0)
                {
                    int x = (n / i) * k + i;
                    if ((x / k) * (x % k) == n)
                        min = Math.Min(min, x);
                }
            }

            Console.WriteLine(min);

        }

    }
}


//#define USE_FILES
//#define MANY_TESTS_IN_INPUT
//#define INCREASE_STACK

#if ONLINE_JUDGE // Defined by Codeforces judging system
#undef USE_FILES
#endif

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

namespace Acm
{
    /// <summary>
    /// For the simplicity of hacking / reading / exploring.
    /// Problem solution is in this class only!
    /// </summary>
    class ProblemSolution
    {
        public LineReader In { get; }

        public TextWriter Out { get; }

        public ProblemSolution(LineReader @in, TextWriter @out)
        {
            In = @in;
            Out = @out;
        }

        /// <summary>
        /// </summary>
        /// <param name="testId">
        /// For multi-test inputs: ID of test, from 1 to T
        /// For single-test inputs: -1
        /// </param>
        public void SolveTest(int testId)
        {
            long[] line = In.Read();
            long a = line[0], b = line[1];

            long diff = Math.Abs(a - b);

            List<long> divisors = new List<long>();

            for (long divisor = 1; divisor * divisor <= diff; divisor++)
            {
                if (diff % divisor == 0)
                {
                    divisors.Add(divisor);

                    if (divisor * divisor != diff)
                        divisors.Add(diff / divisor);
                }
            }

            long answerK = 0;
            long answerLcm = long.MaxValue;
            foreach (long divisor in divisors)
            {
                long k = (divisor - (a % divisor)) % divisor;
                long lcm = (a + k) * (b + k) / divisor;

                if (lcm < answerLcm)
                {
                    answerLcm = lcm;
                    answerK = k;
                }
            }

            Out.WriteLine(answerK);
        }
    }

    // ---------------
    // There is nothing interesting below this line!
    // ---------------

    class Program
    {
        private static LineReader In { get; set; }

        private static TextWriter Out { get; set; }

        public static void Main(string[] args)
        {
#if USE_FILES
            In = new LineReader(File.OpenText("input.txt"));
            Out = new StreamWriter("../../output.txt", false);
#else
            In = new LineReader(Console.In);
            Out = Console.Out;
#endif

                        try
            {
#if INCREASE_STACK
				var thread = new Thread(Solve, 32 * 1024 * 1024);
				thread.Start();
				thread.Join();
#else
                Solve();
#endif
            }
            finally
            {
                Out.Dispose();
            }
        }

        public static void Solve()
        {
#if MANY_TESTS_IN_INPUT
            int t = In.Read();
            for (int i = 1; i <= t; i++)
            {
                new ProblemSolution(In, Out).SolveTest(i);
            }
#else
            new ProblemSolution(In, Out).SolveTest(-1);
#endif
        }
    }

    /// <summary>
    /// Input usability things
    /// </summary>
    class InputLine
    {
        private readonly string _line;

        public InputLine(string line)
        {
            _line = line;
        }

        public static implicit operator string(InputLine line)
        {
            return line._line;
        }

        public static implicit operator int(InputLine line)
        {
            return int.Parse(line._line);
        }

        public static implicit operator int[] (InputLine line)
        {
            return line._line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
        }

        public static implicit operator long[] (InputLine line)
        {
            return line._line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
        }
    }

    class LineReader
    {
        public TextReader Reader { get; }

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

        public InputLine Read()
        {
            string line = Reader.ReadLine();
            return line == null
                ? null
                : new InputLine(line.Trim());
        }
    }
}


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

namespace Neko_does_Maths
{
    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 long Solve(string[] args)
        {
            long a = Next();
            long b = Next();

            long d = Math.Abs(a - b);

            long min = Math.Min(a, b);

            if (d == 0)
                return 0;

            if (min > d)
            {
                long r = a%d;
                if (r == 0)
                    return 0;

                return d - r;
            }

            {
                for (long k = min; k*k<=d; k++)
                {
                    if (d % k == 0)
                        return k - min;
                }
                for (long k = d/min; k >= 1; k--)
                {
                    if (d%k == 0)
                    {
                        return d/k - min;
                    }
                }
                return d - min;
            }
        }

        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;
using System.Collections.Generic;

namespace EightPointSets
{
    public class Point
    {
        public int x;
        public int y;
    }

    public class PointComparer : IComparer<Point>
    {
        public int Compare(Point p1, Point p2)
        {
            if (p1.x < p2.x)
            {
                return -1;
            }
            else if (p1.x == p2.x)
            {
                if (p1.y < p2.y)
                    return -1;
                else
                    return 1;
            }

            return 1;
        }
    }

    class EightPointSets
    {
        static void Main(string[] args)
        {
            string[] input;
            List<Point> point = new List<Point>();

            for (int i = 0; i < 8; i++)
            {
                input = Console.ReadLine().Split();
                point.Add(new Point() { x = int.Parse(input[0]), y = int.Parse(input[1]) });
            }

            point.Sort(new PointComparer());

            bool respectable = point[0].x == point[1].x && point[1].x == point[2].x &&
                               point[3].x == point[4].x &&
                               point[5].x == point[6].x && point[6].x == point[7].x &&
                               point[0].y == point[3].y && point[3].y == point[5].y &&
                               point[1].y == point[6].y &&
                               point[2].y == point[4].y && point[4].y == point[7].y &&
                               point[0].x < point[3].x && point[3].x < point[5].x &&
                               point[0].y < point[1].y && point[1].y < point[2].y;

            if (!respectable)
                Console.WriteLine("ugly");
            else
                Console.WriteLine("respectable");
        }

        private static bool Equals(Point p1, Point p2)
        {
            if (p1.x != p2.x || p1.y != p2.y)
                return false;
            else
                return true;
        }
    }
}


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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            var b = Solve();
            Console.WriteLine(b ? "respectable" : "ugly");
        }

        public static bool Solve()
        {
            var points = new List<Point>();
            for (int i = 0; i < 8; i++)
            {
                var line = Console.ReadLine().Split(' ');
                points.Add(new Point(int.Parse(line[0]), int.Parse(line[1])));
            }

            int maxX = points.Select(p => p.x).Max();
            int minX = points.Select(p => p.x).Min();
            int maxY = points.Select(p => p.y).Max();
            int minY = points.Select(p => p.y).Min();

            int midX, midY;
            try
            {
                midX = points.Select(p => p.x).Where(x => x < maxX && x > minX).First();
                midY = points.Select(p => p.y).Where(y => y < maxY && y > minY).First();
            }
            catch { return false; }

            if (points.Contains(new Point(minX, minY)) &&
                points.Contains(new Point(midX, minY)) &&
                points.Contains(new Point(maxX, minY)) &&
                points.Contains(new Point(minX, midY)) &&
                points.Contains(new Point(maxX, midY)) &&
                points.Contains(new Point(minX, maxY)) &&
                points.Contains(new Point(midX, maxY)) &&
                points.Contains(new Point(maxX, maxY)))
                return true;
            else
                return false;
        }
        struct Point
        {
            public int x;
            public int y;

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

            public override bool Equals(object obj)
            {
                var p = (Point)obj;
                return p.x == x && p.y == y;
            }

            public override int GetHashCode()
            {
                return x.GetHashCode() ^ y.GetHashCode();
            }
        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int32;
namespace Program {
	public class Solver {
		Random rnd = new Random(1);
		public void Solve() {
			var n = ri;
			var m = ri;

			var max = Max(n, m);
			//i-j が正にならないようなやつ
			var pat = new ModInt[max + 5, max + 5];
			pat[0, 0] = 1;
			for (int i = 0; i <= max; i++)
				for (int j = 0; j <= max; j++) {
					if (i < j) pat[i + 1, j] += pat[i, j];
					pat[i, j + 1] += pat[i, j];
				}
			ModInt ans = 0;
			for (int i = 0; i <= n; i++)
				for (int j = 0; j <= m; j++) {
					if (i - j <= 0) continue;
					//Debug.WriteLine($"{i} {j} {pat[j, i]} {pat[n - i, m - j]}");
					ans += (i - j) * pat[n - i, m - j] * pat[j, i - 1];
				}
			//
			//+--+
			//+-+-

			Console.WriteLine(ans);

		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		int ri { get { return sc.Integer(); } }
		long rl { get { return sc.Long(); } }
		double rd { get { return sc.Double(); } }
		string rs { get { return sc.Scan(); } }
		public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n];
			for (int i = 0; i < a.Length; ++i) a[i] = f(i);
			return a;
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}
	static public void Main() {
		Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
		var solver = new Program.Solver();
		var t = new System.Threading.Thread(solver.Solve, 50000000);
		t.Start();
		t.Join();
		//solver.Solve();
		Console.Out.Flush();
	}
}
#endregion
#region Ex
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}

	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}
}

#endregion

#region ModInt
/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt {
	/// <summary>
	/// 剰余を取る値．
	/// </summary>
	public const long Mod = (int)998244853;

	/// <summary>
	/// 実際の数値．
	/// </summary>
	public long num;
	/// <summary>
	/// 値が <paramref name="n"/> であるようなインスタンスを構築します．
	/// </summary>
	/// <param name="n">インスタンスが持つ値</param>
	/// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
	public ModInt(long n) { num = n; }
	/// <summary>
	/// このインスタンスの数値を文字列に変換します．
	/// </summary>
	/// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
	public override string ToString() { return num.ToString(); }
	public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
	public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
	public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
	public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

	/// <summary>
	/// 与えられた 2 つの数値からべき剰余を計算します．
	/// </summary>
	/// <param name="v">べき乗の底</param>
	/// <param name="k">べき指数</param>
	/// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
	public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

	/// <summary>
	/// 与えられた 2 つの数値からべき剰余を計算します．
	/// </summary>
	/// <param name="v">べき乗の底</param>
	/// <param name="k">べき指数</param>
	/// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
	public static ModInt Pow(long v, long k) {
		long ret = 1;
		for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
			if ((k & 1) == 1) ret = ret * v % Mod;
		return new ModInt(ret);
	}
	/// <summary>
	/// 与えられた数の逆元を計算します．
	/// </summary>
	/// <param name="v">逆元を取る対象となる数</param>
	/// <returns>逆元となるような値</returns>
	/// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
	public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
#region Binomial Coefficient
public class BinomialCoefficient {
	public ModInt[] fact, ifact;
	public BinomialCoefficient(int n) {
		fact = new ModInt[n + 1];
		ifact = new ModInt[n + 1];
		fact[0] = 1;
		for (int i = 1; i <= n; i++)
			fact[i] = fact[i - 1] * i;
		ifact[n] = ModInt.Inverse(fact[n]);
		for (int i = n - 1; i >= 0; i--)
			ifact[i] = ifact[i + 1] * (i + 1);
		ifact[0] = ifact[1];
	}
	public ModInt this[int n, int r] {
		get {
			if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
			return fact[n] * ifact[n - r] * ifact[r];
		}
	}
	public ModInt RepeatedCombination(int n, int k) {
		if (k == 0) return 1;
		return this[n + k - 1, k];
	}
}
#endregion


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        int N, M;
        sc.Make(out N, out M);
        ModInt.Build(4040);
        var zero = Create(N + 1, () => new ModInt[Max(N,M) + 1]);
        for (int i = 0; i < Max(N,M) + 1; i++)
        {
            zero[0][i] = 1;
        }
        for (int i = 1; i <= N; i++)
            for (int j = i; j <= Max(M,N); j++)
            {
                zero[i][j] = zero[i - 1][j] + zero[i][j - 1];
            }
        var dp = Create(N + 1, () => new ModInt[M + 1]);
        //1,-1を先頭に追加する
        for (int i = 1; i <= N; i++)
            for (int j = 0; j <= M; j++)
            {
                dp[i][j] += dp[i - 1][j];
                dp[i][j] += ModInt.Comb(i - 1 + j, i - 1);//先頭に1を追加するとmaxは1増える
                if (j > 0)
                {
                    dp[i][j] += dp[i][j - 1];
                    //先頭に-1を追加するとmaxは元から0であるものを除いて1減る
                    dp[i][j] -= ModInt.Comb(i + j - 1, i) - zero[i][j - 1];
                }
            }
        Console.WriteLine(dp[N][M]);
    }
}

public struct ModInt
{
    //public const long MOD = (int)1e9 + 7;
    public const long MOD = 998244853;
    public long Value { get; set; }
    public ModInt(long n = 0) { Value = n; }
    private static ModInt[] fac;//i!
    private static ModInt[] inv;//1/i
    private static ModInt[] facinv;//1/(i!)
    public override string ToString() => Value.ToString();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Value += r.Value;
        if (l.Value >= MOD) l.Value -= MOD;
        return l;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Value -= r.Value;
        if (l.Value < 0) l.Value += MOD;
        return l;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator long(ModInt l) => l.Value;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator ModInt(long n)
    {
        n %= MOD; if (n < 0) n += MOD;
        return new ModInt(n);
    }

    public static ModInt Pow(ModInt m, long n)
    {
        if (n == 0) return 1;
        if (n % 2 == 0) return Pow(m * m, n >> 1);
        else return Pow(m * m, n >> 1) * m;
    }

    public static void Build(int n)
    {
        fac = new ModInt[n + 1];
        facinv = new ModInt[n + 1];
        inv = new ModInt[n + 1];
        inv[1] = 1;
        fac[0] = fac[1] = 1;
        facinv[0] = facinv[1] = 1;
        for (var i = 2; i <= n; i++)
        {
            fac[i] = fac[i - 1] * i;
            inv[i] = MOD - inv[MOD % i] * (MOD / i);
            facinv[i] = facinv[i - 1] * inv[i];
        }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Fac(ModInt n) => fac[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Inv(ModInt n) => inv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt FacInv(ModInt n) => facinv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Comb(ModInt n, ModInt r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        var calc = fac[n];
        calc = calc * facinv[r];
        calc = calc * facinv[n - r];
        return calc;
    }
}
#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }
}
#endregion


using System;
using System.Linq;

class Program
{
    static void Main()
    {
        string str = Console.ReadLine();
        var data = str.Split(new char[] { ' ' });

        int a = int.Parse(data[0]);
        int b = int.Parse(data[1]);

        str = Console.ReadLine();

        int x = 0, y = 0;

        if (a == 0 && b == 0)
        {
            Console.WriteLine("Yes");
            return;
        }

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == 'U') y += 1;
            if (str[i] == 'D') y -= 1;
            if (str[i] == 'L') x -= 1;
            if (str[i] == 'R') x += 1;

            if (x == a && y == b)
            {
                Console.WriteLine("Yes");
                return;
            }
        }

        int xe = x, ye = y;
        x = y = 0;

        if (xe == 0 && ye == 0)
        {
            Console.WriteLine("No");
            return;
        }

        for (int i = 0; i < str.Length; i++)
        {
            if (xe != 0 && (a - x) % xe == 0)
            {
                int step = (a - x) / xe;

                if (step > 0 && ye * step + y == b)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            else if (ye != 0 && (b - y) % ye == 0)
            {
                int step = (b - y) / ye;

                if (step > 0 && xe * step + x == a)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            if (str[i] == 'U') y += 1;
            if (str[i] == 'D') y -= 1;
            if (str[i] == 'L') x -= 1;
            if (str[i] == 'R') x += 1;

            if (xe != 0 && (a - x) % xe == 0)
            {
                int step = (a - x) / xe;

                if (step > 0 && ye * step + y == b)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            else if (ye != 0 && (b - y) % ye == 0)
            {
                int step = (b - y) / ye;

                if (step > 0 && xe * step + x == a)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
        }

        Console.WriteLine("No");
    }
}


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

namespace ACM
{
    class Program
    {
        static void Read(ref int a, ref int b, ref string cmd)
        {
            string in_s = Console.ReadLine();
            string[] pama = in_s.Split(' ');
            a = Convert.ToInt32(pama[0]);
            b = Convert.ToInt32(pama[1]);
            cmd = Console.ReadLine();
        }
        static int check(int dx, int cur_x, int aim_x)
        {
            aim_x -= cur_x;
            if (dx == 0)
            {
                if (aim_x == 0) return -1;
                else return -2;
            }
            else
            {
                if (aim_x % dx == 0 && aim_x / dx >= 0) return aim_x / dx;
                else return -2;
            }
        }
        static void Main(string[] args)
        {
            int a, b;
            string cmd;
            a = b = 0;
            cmd = "";
            Read(ref a,ref b,ref cmd);
            int dx, dy;
            dx = dy = 0;
            for (int i = 0; i < cmd.Length; i++)
            {
             //   Console.Write(cmd[i]);
                switch (cmd[i])
                {
                    case 'D': dy--; break;
                    case 'U': dy++; break;
                    case 'L': dx--; break;
                    case 'R': dx++; break;
                }
            }
            int px, py;
            bool flag;
            px = py = 0;
            flag = false;
           // Console.WriteLine("{0} {1}", dx, dy);
            for (int i = 0; i < cmd.Length; i++)
            {
                //Console.WriteLine("{0}, {1}", px, py);
                int f1 = check(dx, px, a);
                int f2 = check(dy, py, b);
                if(f1 >= -1 && f2 >= -1 && (f1 == f2 || f1 == -1 || f2 == -1))
                {
                    flag = true;
                    break;
                }
                switch (cmd[i])
                {
                    case 'D': py--; break;
                    case 'U': py++; break;
                    case 'L': px--; break;
                    case 'R': px++; break;
                }

            }
            if(flag)Console.WriteLine("Yes");
            else Console.WriteLine("No");

//while (true) ;
        }
    }
}