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

namespace Codeforces
{
    class A
    {
        private static ThreadStart s_threadStart = new A().Go;
        private static bool s_time = false;

        private void Go()
        {
            long k = GetInt();
            long b = GetInt();
            long n = GetInt();
            long t = GetInt();

            if (k == 1)
            {
                long x = (t - 1) / b;
                if (x > n)
                    Wl(0);
                else
                    Wl(n - x);
                return;
            }

            long xx = 1;
            while (xx <= t)
            {
                n--;
                xx = k * xx + b;
            }
            n++;
            if (n < 0) n = 0;
            Wl(n);
            return;

        }

        #region Template

        public static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            Thread main = new Thread(new ThreadStart(s_threadStart), 512 * 1024 * 1024);
            timer.Start();
            main.Start();
            main.Join();
            timer.Stop();
            if (s_time)
                Wl(timer.ElapsedMilliseconds);
        }

        private static IEnumerator<string> ioEnum;
        private static string GetString()
        {
            while (ioEnum == null || !ioEnum.MoveNext())
            {
                ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();
            }

            return ioEnum.Current;
        }

        private static int GetInt()
        {
            return int.Parse(GetString());
        }

        private static long GetLong()
        {
            return long.Parse(GetString());
        }

        private static double GetDouble()
        {
            return double.Parse(GetString());
        }

        private static List<int> GetIntArr(int n)
        {
            List<int> ret = new List<int>(n);
            for (int i = 0; i < n; i++)
            {
                ret.Add(GetInt());
            }
            return ret;
        }

        private static void Wl<T>(T o)
        {
            if (o is double)
            {
                Wld((o as double?).Value, "");
            }
            else if (o is float)
            {
                Wld((o as float?).Value, "");
            }
            else
                Console.WriteLine(o.ToString());
        }

        private static void Wl<T>(IEnumerable<T> enumerable)
        {
            Wl(string.Join(" ", enumerable.Select(e => e.ToString()).ToArray()));
        }

        private static void Wld(double d, string format)
        {
            Wl(d.ToString(format, CultureInfo.InvariantCulture));
        }

        public struct Tuple<T, K> : IComparable<Tuple<T, K>>
            where T : IComparable<T>
            where K : IComparable<K>
        {
            public T Item1;
            public K Item2;

            public Tuple(T t, K k)
            {
                Item1 = t;
                Item2 = k;
            }

            public override bool Equals(object obj)
            {
                var o = (Tuple<T, K>)obj;
                return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);
            }

            public override int GetHashCode()
            {
                return Item1.GetHashCode() ^ Item2.GetHashCode();
            }

            public override string ToString()
            {
                return "(" + Item1 + " " + Item2 + ")";
            }

            #region IComparable<Tuple<T,K>> Members

            public int CompareTo(Tuple<T, K> other)
            {
                int ret = Item1.CompareTo(other.Item1);
                if (ret != 0) return ret;
                return Item2.CompareTo(other.Item2);
            }

            #endregion
        }

        #endregion
    }
}


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

namespace CodeforcesVASYA
{
    class Program
    {
        static void Main(string[] args)
        {

         String [] arr = Console.ReadLine().Split(' ');

         Int64 k=int.Parse(arr[0]);
         Int64 b=int.Parse(arr[1]);
         Int64 n=int.Parse(arr[2]);
         Int64 t=int.Parse(arr[3]);

         Int64 x=1;

 for (n=n; n>0; )
 {

 x=k*x+b;

 if(x>t)
 {

 break;
 }
 else
 {
 n--;
 }

 }

  Console.WriteLine(n);

        }
    }

}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using Number = System.Boolean;
namespace Program
{
    public class Solver
    {

        public void Solve()
        {
            var n = sc.Integer();
            var s = sc.Scan();
            var X = new List<int>();
            var Y = new List<int>();
            var Z = new List<int>();
            for (int i = 0; i < n; i++)
            {
                var c = s[i];
                if (c == 'V') { X.Add(i); }
                else if (c == 'K') { Y.Add(i); }
                else { Z.Add(i); }
            }
            var x = X.Count; var y = Y.Count; var z = Z.Count;
            X.Add(n + 1000000); Y.Add(n + 1000000); Z.Add(n + 1000000);
            var D = new List<int>[] { X, Y, Z };
            var dp = new int[x + 2, y + 2, 2];
            for (int i = 0; i < x + 2; i++)
                for (int j = 0; j < y + 2; j++)
                    for (int k = 0; k < 2; k++)
                        dp[i, j, k] = 1000000;
            dp[0, 0, 0] = 0;
            for (int pos = 0; pos < n; pos++)
            {
                var next = new int[x + 2, y + 2, 2];
                for (int i = 0; i < x + 2; i++)
                    for (int j = 0; j < y + 2; j++)
                        for (int k = 0; k < 2; k++)
                            next[i, j, k] = 1000000;
                for (int a = 0; a < x + 1; a++)
                    for (int b = 0; b < y + 1; b++)
                    {
                        var c = pos - a - b;
                        if (c < 0) continue;
                        if (c > z) continue;
                        var vec = new int[] { a, b, c };
                        for (int k = 0; k < 2; k++)
                        {
                            if (dp[a, b, k] >= 1000000) continue;
                            next[a + 1, b, 1] = Math.Min(next[a + 1, b, 1], dp[a, b, k] + d(X[a], 0, vec, D));
                            if (k != 1)
                                next[a, b + 1, 0] = Math.Min(next[a, b + 1, 0], dp[a, b, k] + d(Y[b], 1, vec, D));
                            next[a, b, 0] = Math.Min(next[a, b, 0], dp[a, b, k] + d(Z[c], 2, vec, D));
                        }
                    }
                dp = next;
            }
            IO.Printer.Out.WriteLine(Math.Min(dp[x, y, 0], dp[x, y, 1]));

        }
        int d(int p, int k, int[] P, List<int>[] D)
        {
            var v = 0;
            for (int i = 0; i < 3; i++)
            {
                if (i == k) continue;
                for (int j = 0; j < P[i]; j++)
                    if (p < D[i][j]) v++;
            }
            return v;
        }

        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 < n; ++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(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    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 = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion


using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using Number = System.Int64;
using KV = System.Collections.Generic.KeyValuePair<int, long>;
namespace Program {
    public class Solver {
        public void Solve() {
            var k = ri;
            var pa = ri;
            var pb = ri;
            var p = pa * ModInt.Inverse(pa + pb);

            var q = pb * ModInt.Inverse(pa + pb);
            var invq = ModInt.Inverse(q);
            var dp = new ModInt[k + 5, k + 5];
            for (int i = 0; i < k + 5; i++)
                for (int j = 0; j < k + 5; j++)
                    dp[i, j].num = -1;
            Func<int, int, ModInt> dfs = null;
            dfs = (a, cnt) => {
                if (cnt >= k) return cnt;
                if (a + cnt >= k) {
                    return cnt + a + invq - 1;
                }
                if (dp[a, cnt].num != -1) return dp[a, cnt];
                ModInt ret = new ModInt(0);
                // a を出す
                ret += p * dfs(a + 1, cnt);
                // b を出す
                ret += q * dfs(a, cnt + a);

                return dp[a, cnt] = ret;
            };
            Console.WriteLine(dfs(1, 0));

        }
        const long INF = 1L << 60;
        int[] dx = { -1, 0, 1, 0 };
        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 < n; ++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.Select(x => x.ToString()).ToArray());
        //return string.Join(st, ie);
    }

    static public void Main() {
        Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Program.Solver();
        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
public struct ModInt {
    public const long Mod = (long)1e9 + 7;
    public long num;
    public ModInt(long n) { num = n; }
    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((int)(l.num * r.num % Mod)); }
    public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }
    public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
    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);
    }
    public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion


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

namespace codeforces
{

    public class Program
    {
        private const int MOD = 1000 * 1000 * 1000 + 7;
        private const int NMax = 1000;

        private static int k;
        private static int pA;
        private static int pB;
        private static int ipB;
        private static int[,] dp = new int[NMax, NMax];
        private static bool[,] marked = new bool[NMax, NMax];

        private static int Add(int a, int b)
        {
            a += b;
            if (a >= MOD)
            {
                a -= MOD;
            }
            return a;
        }

        private static int Mult(int a, int b)
        {
            return (int)(1L * a * b % MOD);
        }

        private static int BinPow(int a, int n)
        {
            int result = 1;
            while (n > 0)
            {
                if (n % 2 == 1)
                {
                    result = Mult(result, a);
                }
                a = Mult(a, a);
                n /= 2;
            }
            return result;
        }

        private static int Solve(int count, int tk)
        {
            if (tk >= k)
            {
                return tk;
            }
            if (count + tk >= k)
            {
                return Add(Add(count, tk), ipB);
            }
            if (marked[count, tk])
            {
                return dp[count, tk];
            }
            marked[count, tk] = true;
            dp[count, tk] = Add(Mult(Solve(count + 1, tk), pA), Mult(Solve(count, tk + count), pB));
            return dp[count, tk];
        }

        private static void Main(string[] args)
        {
            var values = Console.ReadLine().Split(' ');
            k = Convert.ToInt32(values[0]);
            int pa = Convert.ToInt32(values[1]);
            int pb = Convert.ToInt32(values[2]);
            pA = Mult(pa, BinPow(Add(pa, pb), MOD - 2));
            pB = Mult(pb, BinPow(Add(pa, pb), MOD - 2));
            ipB = Mult(pa, BinPow(pb, MOD - 2));
            Console.WriteLine(Solve(1, 0));
        }
    }
}


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

namespace Ilya_and_Escalator
{
    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[] ss = reader.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int t = int.Parse(ss[2]);
            double p = double.Parse(ss[1], CultureInfo.InvariantCulture);
            double q = 1 - p;
            var nn = new double[n + 1];
            nn[0] = 1;

            for (int i = 0; i < t; i++)
            {
                nn[n] += p*nn[n - 1];

                for (int j = n - 1; j > 0; j--)
                {
                    nn[j] = q*nn[j] + p*nn[j - 1];
                }

                nn[0] *= q;
            }

            double sum = 0;

            for (int i = 1; i <= n; i++)
            {
                sum += i*nn[i];
            }

            writer.WriteLine(sum.ToString("#0.0000000", CultureInfo.InvariantCulture));
            writer.Flush();
        }
    }
}


// using a C# contest template, relevant code is at the bottom in the Run() function

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

class ProblemD {
    static string inputFileName = "../../input.txt";
    static StreamReader fileReader;
    static string[] inputTokens;
    static int curInputTokenIndex;
    static bool isLocal = Type.GetType("HaitaoLocal") != null;
    static string NextToken() {
        string ret = "";
        while (ret == "") {
            if (inputTokens == null || curInputTokenIndex >= inputTokens.Length) {
                string line;
                if (isLocal) {
                    line = fileReader.ReadLine();
                    if (line == null) {
                        throw new Exception("Error: out of input tokens!");
                    }
                } else {
                    line = Console.ReadLine();
                }
                inputTokens = line.Split();
                curInputTokenIndex = 0;
            }
            ret = inputTokens[curInputTokenIndex++];
        }
        return ret;
    }
    static int ri { get { return RI(); } }
    static string rs { get { return RS(); } }
    static long rl { get { return RL(); } }
    static double rd { get { return RD(); } }
    static int RI() {
        return Int32.Parse(NextToken());
    }
    static string RS() {
        return NextToken();
    }
    static long RL() {
        return Int64.Parse(NextToken());
    }
    static double RD() {
        return Double.Parse(NextToken());
    }
    static int[] RIA(int length) {
        int[] ret = new int[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RI();
        }
        return ret;
    }
    static string[] RSA(int length) {
        string[] ret = new string[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RS();
        }
        return ret;
    }
    static long[] RLA(int length) {
        long[] ret = new long[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RL();
        }
        return ret;
    }
    static double[] RDA(int length) {
        double[] ret = new double[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RD();
        }
        return ret;
    }
    static StringBuilder outputBuilder;
    static CultureInfo outputCulture = new CultureInfo("en-US");
    static void Out(object obj) {
        Type type = obj.GetType();
        string str = obj.ToString();
        if (type == typeof(double) || type == typeof(float)) {
            str = ((double)obj).ToString(outputCulture);
        }
        outputBuilder.Append(str + " ");
    }
    static void Outl() {
        Outl("");
    }
    static void Outl(object obj) {
        Out(obj);
        outputBuilder.Append("\n");
    }
    static void Flush() {
        if (isLocal) {
            ConsoleColor t = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine();
            Console.WriteLine(outputBuilder.ToString());
            Console.ForegroundColor = t;
        } else {
            Console.WriteLine(outputBuilder.ToString());
        }
        outputBuilder = new StringBuilder();
    }
    static void Log(string label, object obj) {
        if (!isLocal) return;

        ConsoleColor t = Console.ForegroundColor;
        Console.ForegroundColor = ConsoleColor.Gray;
        Console.Write(label + ": ");
        Console.ForegroundColor = t;
        Log(obj);
    }
    static void Log(object obj) {
        if (!isLocal) return;

        ConsoleColor t = Console.ForegroundColor;
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine(ToStringRecursive(obj));
        Console.ForegroundColor = t;
    }
    static string ToStringRecursive(object obj) {
        StringBuilder sb = new StringBuilder();
        if (!(obj is string) && (obj is System.Collections.IEnumerable)) {
            System.Collections.IEnumerable en = obj as System.Collections.IEnumerable;
            sb.Append("{");
            bool first = true;
            foreach (object el in en) {
                if (!first) sb.Append(", ");
                sb.Append(ToStringRecursive(el));
                first = false;
            }
            sb.Append("}");
            return sb.ToString();
        }
        return obj.ToString();
    }

    public static void Main(string[] args) {
        long startTick = 0;
        if (isLocal) {
            startTick = Environment.TickCount;
            fileReader = new StreamReader(inputFileName);
        }

        outputBuilder = new StringBuilder();
        Run();
        if (isLocal) {
            ConsoleColor t = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine();
            Console.WriteLine(outputBuilder.ToString());
            Console.WriteLine();
            Console.ForegroundColor = t;
        } else {
            Console.WriteLine(outputBuilder.ToString());
        }

        if (isLocal) {
            long runTime = Environment.TickCount - startTick;
            if (runTime > 32) {
                Log("time", runTime);
                Log("");
            }
        }
    }

    static void Run() {
        long n = rl;
        long ans = 0;
        if(n==2) {
            ans = 1;
        } else if(n==3) {
            ans = 3;
        } else if(n==4) {
            ans = 6;
        } else {
            long l = 9;
            while(f(l*10+9, n)>0) {
                l = l * 10 + 9;
            }
            Log("l " + l);
            for(int a=0; a<=9; a++) {
                ans += f(a * (l+1) + l, n);
                Log(ans);
            }
        }
        Outl(ans);
    }

    static long f(long a, long b) {
        if (b + b < a) return 0;
        if (b >= a) return f(a, a-1);
        return b - a/2;
    }
}


using System;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            UInt64 n = UInt64.Parse(Console.ReadLine());
            UInt64 sum = n + (n - 1);
            UInt64 result = 0;
            if (n <= 4)
                result = (n - 1) * n / 2;
            else
            {
                char[] bad = { '0', '1', '2', '3', '4', '5', '6', '7', '8' };
                if (sum.ToString().IndexOfAny(bad) == -1)
                    result = 1;
                else
                {
                    UInt64 count = (UInt64)sum.ToString().Length;
                    string devt = "";
                    for (UInt64 i = 0; i < count - 1; i++)
                        devt += "9";
                    for (int i = 0; i < 9; i++)
                    {
                        UInt64 curent = UInt64.Parse(i.ToString() + devt);
                        if (curent <= (n + 1))
                            result += (curent / 2);
                        else if (!(curent > n + (n - 1)))
                            result += ((n - (curent - n)) / 2 + 1);
                    }
                }
            }
            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution{
	 static void Main(string[] args) {
           const int MOD = 1000000007;
            int n = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), x => Convert.ToInt32(x));
            C = new long[200, 200];
            C[0, 0] = 1;
            for (int i = 1; i < 200; i++) {
                C[i, 0] = C[i, i] = 1;
                for (int j = 1; j <= i; j++)
                    C[i, j] = (C[i - 1, j] + C[i - 1, j - 1]) % MOD;
            }

            long ans = 0;
            for (int k = a.Sum(); k <= n; k++) {

                long[,] dp = new long[110, 30];
                dp[k, 0] = 1;

                for (int j = 0; j < 10; j++)
                    for (int i = a[j]; i <= k; i++)
                        for (int l = a[j]; l <= i; l++) {
                            if (j == 0) dp[i - l, j + 1] = (dp[i - l, j + 1] + dp[i, j] * CNK(i - 1, l) % MOD) % MOD;
                            else dp[i - l, j + 1] = (dp[i - l, j + 1] + dp[i, j] * CNK(i, l) % MOD) % MOD;
                        }

                ans += dp[0, 10];
                ans %= MOD;
            }

            Console.WriteLine(ans);
	 }
     static long[,] C;
        static long CNK(long n, long k) {
            if (k > n || k < 0) return 0;
            if (k == n || k == 0) return 1;
            return C[n, k];
        }
}


//

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

namespace sar_cs
{
    static class Helpers
    {
        // Mono lacks this override of string.Join()
        public static string Join<T>(this IEnumerable<T> objs, string sep)
        {
            var sb = new StringBuilder();
            foreach (var s in objs) { if (sb.Length != 0) sb.Append(sep); sb.Append(s); }
            return sb.ToString();
        }

        public static string AsString(this double a, int digits)
        {
            return a.ToString("F" + digits, CultureInfo.InvariantCulture);
        }

        public static Stopwatch SW = Stopwatch.StartNew();
    }

    public class Program
    {
        #region Helpers

        public class Parser
        {
            const int BufSize = 8000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1;
                    else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-') { sign = 1; c = Read(); }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = 1;
                    c = Read();
                }
                int len = 0;

                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public int ReadLnInt()
            {
                int res = ReadInt(); ReadLine(); return res;
            }

            public long ReadLnLong()
            {
                long res = ReadLong(); ReadLine(); return res;
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-') { sign = -1; c = Read(); }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c); c = Read();
                }

                Back();
                var res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c); c = Read();
                }
                if (c == 13) { c = Read(); if (c != 10) Back(); }
                return sb.ToString();
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }

            public int[] ReadIntArr(int n)
            {
                var a = new int[n]; for (int i = 0; i < n; i++) a[i] = ReadInt(); return a;
            }

            public long[] ReadLongArr(int n)
            {
                var a = new long[n]; for (int i = 0; i < n; i++) a[i] = ReadLong(); return a;
            }
        }

        static void pe() { Console.WriteLine("???"); Environment.Exit(0); }
        static void re() { Environment.Exit(55); }
        static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
        static int Sqr(int a) { return a * a; }
        static long SqrL(int a) { return (long)a * a; }
        static long Sqr(long a) { return a * a; }
        static double Sqr(double a) { return a * a; }

        static StringBuilder sb = new StringBuilder();
        static Random rand = new Random(5);

        #endregion Helpers

        static int[] minQ;

        const int M = 1000000007;

        static int[,] C = GetCountModTable(100, 100, M);

        static public int[,] GetCountModTable(int maxN, int maxK, int Mod)
        {
            if (maxN < 0 || maxK < 0) throw new ArgumentException();
            if (Mod > int.MaxValue / 2) throw new ArgumentOutOfRangeException();
            var result = new int[maxN + 1, maxK + 1];
            for (int n = 0; n <= maxN; n++)
                for (int k = 0; k <= maxK; k++)
                    if (k == 0) result[n, k] = 1;
                    else if (n == 0) result[n, k] = 0;
                    else result[n, k] = (result[n - 1, k] + result[n, k - 1]) % Mod;
            return result;
        }

        static int[,] fcache;

        static long f(int n, int d)
        {
            checked
            {
                //if (d == 10) return n == 0 ? 1 : 0;
                if (n < minQ[d]) return 0;
                //if (n == 0) return 0;

                if (n == 0 || d > 9) throw new Exception();

                if (fcache[n, d] != 0) return fcache[n, d] - 1;

                long result = 0;
                for (int i = minQ[d]; i <= n; i++)
                {
                    long t1;

                    if (i == 0)
                    {
                        if (d == 9) t1 = n == 0 ? 1 : 0;
                        else t1 = f(n, d + 1);
                    }
                    else if (i == n)
                    {
                        if (minQ.Skip(d + 1).Any(q => q > 0)) t1 = 0;
                        else if (d == 0 && i > 1) t1 = 0;
                        else t1 = 1;
                    }
                    else
                    {
                        if (d == 9)
                            t1 = 0;
                        else
                        {
                            t1 = f(n - i, d + 1);
                            var t2 = d == 0 ? C[n - i, i] : C[n - i + 1, i];
                            t1 *= t2;
                        }
                    }

                    t1 %= M;
                    result = (result + t1) % M;
                }

                fcache[n, d] = (int)result + 1;
                return result;
            }
        }

        static void Main(string[] args)
        {
            checked
            {
                //Console.SetIn(File.OpenText("_input"));
                var parser = new Parser();
                while (!parser.SeekEOF)
                {
                    int n = parser.ReadInt();
                    minQ = parser.ReadIntArr(10);

                    //for (int i = 100; i <= 999; i++) if (i.ToString().Contains('0') && i.ToString().Contains('1')) Console.WriteLine(i);
                    //Console.WriteLine("");

                    //Console.WriteLine(f(3, 0));

                    //for (int d = 0; d <= 9; d++)
                    //{
                    //    Console.Write("d=" + d + ": ");
                    //    for (int i = 1; i <= n; i++)
                    //        Console.Write(f(i, d) + " ");
                    //    Console.WriteLine();
                    //}

                    fcache = new int[101, 10];
                    long result = 0;
                    for (int i = 1; i <= n; i++)
                        result = (result + f(i, 0)) % M;

                    if (minQ[0] <= 1 && minQ.Skip(1).All(q => q == 0)) result--;

                    Console.WriteLine(result);
                }
            }
        }

        //static void Main(string[] args)
        //{
        //    new Thread(Main2, 50 << 20).Start();
        //}
    }
}


using System;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Mathematics;
using CompLib.String;

public class Program
{
    int N;
    string S;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        S = sc.Next();

        int cnt = 0;
        int min = 0;
        foreach (var c in S)
        {
            if (c == '(') cnt++;
            else cnt--;
            min = Math.Min(min, cnt);
        }
        /*
         * Sを部分文字列に含むカッコ列の個数
         */

        // iで間違えたときどこに飛ぶか?
        int[] next = new int[S.Length];
        for (int i = 0; i < S.Length; i++)
        {
            if (i == 0)
            {
                next[i] = 0;
                continue;
            }

            bool f2 = false;
            for (int len = i; len >= 1; len--)
            {
                bool f = true;
                for (int j = 0; f && j < len - 1; j++)
                {
                    f &= S[j] == S[i - len + 1 + j];
                }
                if (!f) continue;
                if (S[len - 1] != S[i])
                {
                    next[i] = len;
                    f2 = true;
                    break;
                }
            }

        }

        // i文字目まで作る、カウンタ、Sより前、Sより後, Sの何文字までできたか?
        var dp = new ModInt[2 * N + 1, N + 1, S.Length, 2];
        dp[0, 0, 0, 0] = 1;
        for (int i = 0; i < 2 * N; i++)
        {
            for (int j = 0; j <= N; j++)
            {
                for (int k = 0; k < S.Length; k++)
                {
                    // (
                    if (j + 1 <= N)
                    {
                        if (S[k] == '(')
                        {
                            if (k + 1 == S.Length)
                            {
                                dp[i + 1, j + 1, 0, 1] += dp[i, j, k, 0];
                            }
                            else
                            {
                                dp[i + 1, j + 1, k + 1, 0] += dp[i, j, k, 0];
                            }
                        }
                        else
                        {
                            // どこに飛ぶ
                            dp[i + 1, j + 1, next[k], 0] += dp[i, j, k, 0];
                        }

                    }

                    if (j - 1 >= 0)
                    {
                        if (S[k] == ')')
                        {
                            if (k + 1 == S.Length)
                            {
                                dp[i + 1, j - 1, 0, 1] += dp[i, j, k, 0];
                            }
                            else
                            {
                                dp[i + 1, j - 1, k + 1, 0] += dp[i, j, k, 0];
                            }
                        }
                        else
                        {
                            dp[i + 1, j - 1, next[k], 0] += dp[i, j, k, 0];
                        }

                    }
                }

                if (j + 1 <= N)
                {
                    dp[i + 1, j + 1, 0, 1] += dp[i, j, 0, 1];
                }
                if (j - 1 >= 0)
                {
                    dp[i + 1, j - 1, 0, 1] += dp[i, j, 0, 1];
                }
            }
        }

        Console.WriteLine(dp[2 * N, 0, 0, 1]);
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

namespace CompLib.String
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    public static partial class StringACL
    {
        private const int ThresholdNative = 10;
        private const int ThresholdDoubling = 40;

        #region SuffixArray
        public static int[] SuffixArray(int[] s, int upper)
        {
            Debug.Assert(0 <= upper);

            // C++みたいに内部で何もしないループをスキップするのか?
            // してくれるなら #ifいらない
#if DEBUG
            foreach (var d in s)
            {
                Debug.Assert(0 <= d && d <= upper);
            }
#endif
            return SAIS(s, upper);
        }

        public static int[] SuffixArray<T>(T[] s, Comparison<T> cmp)
        {
            int n = s.Length;
            int[] idx = new int[n];
            for (int i = 0; i < n; i++)
            {
                idx[i] = i;
            }

            Array.Sort(idx, (l, r) => cmp(s[l], s[r]));

            int[] s2 = new int[n];
            int now = 0;
            for (int i = 0; i < n; i++)
            {
                if (0 < i && cmp(s[idx[i - 1]], s[idx[i]]) != 0) now++;
                s2[idx[i]] = now;
            }

            return SAIS(s2, now);
        }
        public static int[] SuffixArray<T>(T[] s)
        {
            return SuffixArray(s, Comparer<T>.Default.Compare);
        }

        /// <summary>
        /// 長さnの文字列のsuffixArrayを返す
        /// </summary>
        /// <remarks>
        /// <para>{0,1,2,...,n-1}の順列、s[sa[i],n) < s[sa[i+1],n)</para>
        /// <para>suffixArrayの辞書順</para>
        /// </remarks>
        /// <param name="s"></param>
        /// <returns></returns>
        public static int[] SuffixArray(string s)
        {
            int n = s.Length;
            int[] s2 = new int[n];
            for (int i = 0; i < n; i++)
            {
                s2[i] = s[i];
            }
            return SAIS(s2, 255);
        }

        // O(n^2)
        private static int[] SANative(int[] s)
        {
            int n = s.Length;
            int[] sa = new int[n];
            for (int i = 0; i < n; i++)
            {
                sa[i] = i;
            }
            Array.Sort(sa, (l, r) =>
             {
                 // 同じなら0
                 if (l == r) return 0;
                 // 順番に見る
                 while (l < n && r < n)
                 {

                     if (s[l] != s[r]) return s[l].CompareTo(s[r]);
                     l++;
                     r++;
                 }

                 // indexが大きい方が辞書順で小さい
                 return r.CompareTo(l);
             });
            return sa;
        }
        private static int[] SADoubling(int[] s)
        {
            int n = s.Length;
            int[] sa = new int[n];
            int[] rnk = new int[n];
            int[] tmp = new int[n];
            Array.Copy(s, rnk, n);
            for (int i = 0; i < n; i++)
            {
                sa[i] = i;
            }

            for (int k = 1; k < n; k *= 2)
            {
                Comparison<int> cmp = (int x, int y) =>
                {
                    if (rnk[x] != rnk[y]) return rnk[x].CompareTo(rnk[y]);
                    int rx = x + k < n ? rnk[x + k] : -1;
                    int ry = y + k < n ? rnk[y + k] : -1;
                    return rx.CompareTo(ry);
                };

                Array.Sort(sa, cmp);
                tmp[sa[0]] = 0;
                for (int i = 1; i < n; i++)
                {
                    tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) < 0 ? 1 : 0);
                }

                var t = tmp;
                tmp = rnk;
                rnk = t;
            }

            return sa;
        }

        private static int[] SAIS(int[] s, int upper)
        {
            int n = s.Length;
            if (n == 0) return new int[0];
            if (n == 1) return new int[1];
            if (n == 2)
            {
                if (s[0] < s[1])
                {
                    return new int[] { 0, 1 };
                }
                else
                {
                    return new int[] { 1, 0 };
                }
            }

            if (n < ThresholdNative)
            {
                return SANative(s);
            }

            if (n < ThresholdDoubling)
            {
                return SADoubling(s);
            }

            int[] sa = new int[n];
            bool[] ls = new bool[n];

            for (int i = n - 2; i >= 0; i--)
            {
                ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]);
            }

            int[] sumL = new int[upper + 1];
            int[] sumS = new int[upper + 1];

            for (int i = 0; i < n; i++)
            {
                if (!ls[i])
                {
                    sumS[s[i]]++;
                }
                else
                {
                    sumL[s[i] + 1]++;
                }
            }

            for (int i = 0; i <= upper; i++)
            {
                sumS[i] += sumL[i];
                if (i < upper) sumL[i + 1] += sumS[i];
            }

            Action<List<int>> induce = (List<int> lms) =>
          {
              for (int i = 0; i < n; i++)
              {
                  sa[i] = -1;
              }

              int[] buf = new int[upper + 1];
              Array.Copy(sumS, buf, upper + 1);

              foreach (var d in lms)
              {
                  if (d == n) continue;
                  sa[buf[s[d]]++] = d;
              }

              Array.Copy(sumL, buf, upper + 1);
              sa[buf[s[n - 1]]++] = n - 1;
              for (int i = 0; i < n; i++)
              {
                  int v = sa[i];
                  if (v >= 1 && !ls[v - 1])
                  {
                      sa[buf[s[v - 1]]++] = v - 1;
                  }
              }

              Array.Copy(sumL, buf, upper + 1);

              for (int i = n - 1; i >= 0; i--)
              {
                  int v = sa[i];
                  if (v >= 1 && ls[v - 1])
                  {
                      sa[--buf[s[v - 1] + 1]] = v - 1;
                  }
              }
          };

            int[] lmsMap = new int[n + 1];
            for (int i = 0; i <= n; i++)
            {
                lmsMap[i] = -1;
            }

            int m = 0;
            for (int i = 1; i < n; i++)
            {
                if (!ls[i - 1] && ls[i])
                {
                    lmsMap[i] = m++;
                }
            }

            List<int> lmsL = new List<int>(m);
            for (int i = 1; i < n; i++)
            {
                if (!ls[i - 1] && ls[i])
                {
                    lmsL.Add(i);
                }
            }

            induce(lmsL);

            if (m != 0)
            {
                List<int> sortedLms = new List<int>(m);
                foreach (var v in sa)
                {
                    if (lmsMap[v] != -1) sortedLms.Add(v);
                }

                int[] recS = new int[m];

                int recUpper = 0;
                recS[lmsMap[sortedLms[0]]] = 0;
                for (int i = 1; i < m; i++)
                {
                    int l = sortedLms[i - 1], r = sortedLms[i];
                    int endL = (lmsMap[l] + 1 < m) ? lmsL[lmsMap[l] + 1] : n;
                    int endR = (lmsMap[r] + 1 < m) ? lmsL[lmsMap[r] + 1] : n;

                    bool same = true;

                    if (endL - l != endR - r)
                    {
                        same = false;
                    }
                    else
                    {
                        while (l < endL)
                        {
                            if (s[l] != s[r])
                            {
                                break;
                            }
                            l++;
                            r++;
                        }

                        if (l == n || s[l] != s[r]) same = false;
                    }

                    if (!same) recUpper++;
                    recS[lmsMap[sortedLms[i]]] = recUpper;
                }

                var recSa = SAIS(recS, recUpper);

                for (int i = 0; i < m; i++)
                {
                    sortedLms[i] = lmsL[recSa[i]];
                }

                induce(sortedLms);
            }
            return sa;
        }
        #endregion // SuffixArray

        #region LCPArray
        /// <summary>
        /// sのLCPArrayとして長さ n-1の配列を返す
        /// </summary>
        /// <remarks>
        /// <para>res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common Prefixの長さ</para>
        /// <para>O(n)</para>
        /// </remarks>
        /// <typeparam name="T"></typeparam>
        /// <param name="s"></param>
        /// <param name="sa"></param>
        /// <param name="cmp"></param>
        /// <returns></returns>
        public static int[] LCPArray<T>(T[] s, int[] sa, Comparison<T> cmp)
        {
            int n = s.Length;
            Debug.Assert(n >= 1);
            int[] rnk = new int[n];
            for (int i = 0; i < n; i++)
            {
                rnk[sa[i]] = i;
            }

            int[] lcp = new int[n - 1];
            int h = 0;
            for (int i = 0; i < n; i++)
            {
                if (h > 0) h--;
                if (rnk[i] == 0) continue;
                int j = sa[rnk[i] - 1];
                for (; j + h < n && i + h < n; h++)
                {
                    if (cmp(s[j + h], s[i + h]) != 0) break;
                }
                lcp[rnk[i] - 1] = h;
            }

            return lcp;
        }

        /// <summary>
        /// sのLCPArrayとして長さ n-1の配列を返す
        /// </summary>
        /// <remarks>
        /// <para>res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common Prefixの長さ</para>
        /// <para>O(n)</para>
        /// </remarks>
        /// <typeparam name="T"></typeparam>
        /// <param name="s"></param>
        /// <param name="sa"></param>
        /// <returns></returns>
        public static int[] LCPArray<T>(T[] s, int[] sa)
        {
            return LCPArray(s, sa, Comparer<T>.Default.Compare);
        }
        /// <summary>
        /// sのLCPArrayとして長さ n-1の配列を返す
        /// </summary>
        /// <remarks>
        /// <para>res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common Prefixの長さ</para>
        /// <para>O(n)</para>
        /// </remarks>
        /// <typeparam name="T"></typeparam>
        /// <param name="s"></param>
        /// <param name="sa"></param>
        /// <returns></returns>
        public static int[] LCPArray(string s, int[] sa)
        {
            //int n = s.Length;
            //int[] s2 = new int[n];
            //for (int i = 0; i < n; i++)
            //{
            //    s2[i] = s[i];
            //}
            return LCPArray(s.ToCharArray(), sa);
        }

        #endregion // LCPArray

        #region ZAlgorithm

        /// <summary>
        /// 長さnの配列sについて sと s[i,n)のLCPの長さを返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="s"></param>
        /// <param name="eq"></param>
        /// <returns></returns>
        public static int[] ZAlgorithm<T>(T[] s, EqualityComparer<T> eq)
        {
            int n = s.Length;
            if (n == 0) return new int[0];
            int[] z = new int[n];
            z[0] = 0;
            for (int i = 1, j = 0; i < n; i++)
            {
                ref int k = ref z[i];
                k = (j + z[j] <= i) ? 0 : Math.Min(j + z[j] - i, z[i - j]);
                while (i + k < n && eq.Equals(s[k], s[i + k])) k++;
                if (j + z[j] < i + z[i]) j = i;
            }
            z[0] = n;
            return z;
        }

        /// <summary>
        /// 長さnの配列sについて sと s[i,n)のLCPの長さを返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="s"></param>
        /// <returns></returns>
        public static int[] ZAlgorithm<T>(T[] s)
        {
            return ZAlgorithm(s, EqualityComparer<T>.Default);
        }

        /// <summary>
        /// 長さnの文字列sについて sと s[i,n)のLCPの長さを返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="s"></param>
        /// <returns></returns>
        public static int[] ZAlgorithm(string s)
        {
            return ZAlgorithm(s.ToCharArray());
        }

        #endregion
    }
}

// https://bitbucket.org/camypaper/complib
namespace CompLib.Mathematics
{
    #region ModInt
    /// <summary>
    /// [0,<see cref="Mod"/>) までの値を取るような数
    /// </summary>
    public struct ModInt
    {
        /// <summary>
        /// 剰余を取る値．
        /// </summary>
        public const long Mod = (int)1e9 + 7;
        // public const long Mod = 998244353;

        /// <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
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

namespace CF954G
{
    class Program
    {
		public class Global
		{
			public static int[,] len;
			public static int[,,,] Dp;
		}

		static void Main(string[] args)
        {
			const int mod = 1000000007;

			int len = Convert.ToInt32(Console.ReadLine());
			string s = Console.ReadLine(), t = "";

			Global.len = new int[s.Length + 1, 2];
			Global.Dp = new int[(len << 1) + 5, (len << 1) + 5, s.Length + 5, 2];
			Global.Dp[0, 0, 0, 0] = 1;

			if(s[0] == '(') Global.len[0, 0] = 1;
			else Global.len[0, 1] = 1;
			for(int i = 0; i < s.Length; i++) {
				t += s[i];t += '(';
				Global.len[i + 1, 0] = Match(s, t);
				t = t.Remove(t.Length - 1, 1); t += ')';
				Global.len[i + 1, 1] = Match(s, t);
				t = t.Remove(t.Length - 1, 1);
			}

			for(int i = 0; i < (len << 1); i++)
				for(int j = 0; j <= len; j++)
					for(int k = 0; k <= s.Length; k++)
						for(int fin = 0; fin <= 1; fin++) {
							if(Global.Dp[i, j, k, fin] == 0) continue;
							if(j < len) {
								Global.Dp[i + 1, j + 1, Global.len[k, 0], fin | (Global.len[k, 0] == s.Length ? 1 : 0)] += Global.Dp[i, j, k, fin];
								Global.Dp[i + 1, j + 1, Global.len[k, 0], fin | (Global.len[k, 0] == s.Length ? 1 : 0)] %= mod;
							}
							if(j > 0) {
								Global.Dp[i + 1, j - 1, Global.len[k, 1], fin | (Global.len[k, 1] == s.Length ? 1 : 0)] += Global.Dp[i, j, k, fin];
								Global.Dp[i + 1, j - 1, Global.len[k, 1], fin | (Global.len[k, 1] == s.Length ? 1 : 0)] %= mod;
							}
						}

			int _count = 0, final_Len = len << 1;
			for(int i = 0; i <= s.Length; i++) {
				_count += Global.Dp[final_Len, 0, i, 1];
				_count %= mod;
			}

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

		static int Match(string a,string t) {
			for(int i = Math.Min(t.Length, a.Length); i > 0; i--)
				if(a.Substring(0, i) == t.Substring(t.Length - i, i))
					return i;
			return 0;
		}
	}
}


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

class ProblemD {
    static string inputFileName = "../../input.txt";
    static StreamReader fileReader;
    static string[] inputTokens;
    static int curInputTokenIndex;
    static string NextToken() {
        string ret = "";
        while (ret == "") {
            if (inputTokens == null || curInputTokenIndex >= inputTokens.Length) {
                string line;
                if (Type.GetType("HaitaoLocal") != null) {
                    if (fileReader == null) {
                        fileReader = new StreamReader(inputFileName);
                    }
                    line = fileReader.ReadLine();
                    if (line == null) {
                        throw new Exception("Error: out of input tokens!");
                    }
                } else {
                    line = Console.ReadLine();
                }
                inputTokens = line.Split();
                curInputTokenIndex = 0;
            }
            ret = inputTokens[curInputTokenIndex++];
        }
        return ret;
    }
    static int ReadInt() {
        return Int32.Parse(NextToken());
    }
    static string ReadString() {
        return NextToken();
    }
    static long ReadLong() {
        return Int64.Parse(NextToken());
    }
    static int[] ReadIntArray(int length) {
        int[] ret = new int[length];
        for (int i = 0; i < length; i++) {
            ret[i] = ReadInt();
        }
        return ret;
    }
    static string[] ReadStringArray(int length) {
        string[] ret = new string[length];
        for (int i = 0; i < length; i++) {
            ret[i] = ReadString();
        }
        return ret;
    }
    static long[] ReadLongArray(int length) {
        long[] ret = new long[length];
        for (int i = 0; i < length; i++) {
            ret[i] = ReadLong();
        }
        return ret;
    }
    static string DoubleToString(double d) {
        return d.ToString(new CultureInfo("en-US"));
    }

    public static void Main(string[] args) {
        int Q = 1000001;
        bool[] notPrime = new bool[Q];
        notPrime[0] = true;
        notPrime[1] = true;
        for (int i = 2; i <= Math.Sqrt(notPrime.Length); i++) {
            if (!notPrime[i]) {
                for (int j = i * 2; j < notPrime.Length; j += i) {
                    notPrime[j] = true;
                }
            }
        }
        List<int> primes = new List<int>();
        for(int i=0; i<Q; i++) if(!notPrime[i]) primes.Add(i);
        long N = ReadLong();
        List<long> factors = new List<long>();
        for (long i = 1; i <= 1000000; i++) {
            if (N % i != 0) continue;
            if (i * i > N) break;
            factors.Add(i);
            if(i*i!=N) factors.Add(N / i);
        }
        factors.Sort();
        Dictionary<long, long> pmap = new Dictionary<long, long>();
        foreach (long f in factors) {
            long k = f - 1;
            bool flag = true;
            foreach (int p in primes) {
                if (k % p == 0) {
                    flag = false;
                    long x = 1;
                    while (x < k) x *= p;
                    if (x == k) {
                        pmap.Add(f, p);
                    } else {
                        break;
                    }
                }
            }
            if (flag && k>1) pmap.Add(f, k);
        }
        //foreach (long key in pmap.Keys) {
        //    Console.WriteLine(key + " " + pmap[key]);
        //}
        Dictionary<long, long> dp = new Dictionary<long, long>();

        foreach (long i in factors) {
            dp[i] = 0;
        }
        dp[1] = 1;
        Dictionary<long,long> used = new Dictionary<long, long>();
        foreach (long key in pmap.Keys) {
            long p = pmap[key];
            if (used.ContainsKey(p)) continue;
            used.Add(p, 0);

            Dictionary<long, long> toAdd = new Dictionary<long, long>();
            foreach (long k2 in pmap.Keys) {
                if (pmap[k2] != p) continue;
                foreach (long f in factors) {
                    if(f%k2!=0) continue;
                    if (toAdd.ContainsKey(f)) toAdd[f] += dp[f / k2];
                    else toAdd[f] = dp[f / k2];
                }
            }
            foreach (long f in toAdd.Keys) {
                dp[f] += toAdd[f];
            }
        }

        //foreach (long key in factors) {
        //    Console.WriteLine(key + " " + dp[key]);
        //}

        Console.WriteLine(dp[N]);

    }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    int Gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }

    private const int SIEVE_SIZE = 1000010;
    private readonly bool[] isComposite = new bool[SIEVE_SIZE + 1];
    private readonly IList<int> primes = new List<int>();
    void Sieve()
    {
        for (int i = 2; i * i <= SIEVE_SIZE; i++)
            if (!isComposite[i])
                for (int j = i * i; j <= SIEVE_SIZE; j += i)
                    isComposite[j] = true;
        for (int i = 2; i <= SIEVE_SIZE; i++)
            if (!isComposite[i])
                primes.Add(i);
    }

    public void Solve()
    {
        Sieve();

        long a = ReadLong();
        if (a == 1)
        {
            Write(1);
            return;
        }
        var d = new SDictionary<long, int> { { a, 1 } };
        int ans = 0;
        var ts = DateTime.Now;
        for (int i = 0; i < primes.Count; i++)
        {
            bool ok = false;
            for (long x = primes[i]; !ok && x < a; x *= primes[i])
                if (a % (x + 1) == 0)
                    ok = true;
            if (!ok)
                continue;

            var toAdd = new List<Tuple<long, int>>();
            var toRemove = new List<long>();
            foreach (var p in d)
            {
                if (p.Key <= primes[i])
                    toRemove.Add(p.Key);
                for (long x = primes[i]; x < p.Key; x *= primes[i])
                    if (p.Key % (x + 1) == 0)
                    {
                        long y = p.Key / (x + 1);
                        if (y == 1)
                            ans += p.Value;
                        else if (y > primes[i] && y % 2 == 0)
                            toAdd.Add(Tuple.Create(y, p.Value));
                    }
            }
            foreach (int x in toRemove)
                d.Remove(x);
            foreach (var p in toAdd)
                d[p.Item1] += p.Item2;
        }
        //Write((DateTime.Now - ts).TotalMilliseconds);

        foreach (var p in d)
            if (p.Key > SIEVE_SIZE)
            {
                long x = p.Key - 1;
                bool ok = true;
                for (int i = 0; ok && 1L * primes[i] * primes[i] <= x; i++)
                    if (x % primes[i] == 0)
                        ok = false;
                if (ok)
                    ans += p.Value;
            }

        Write(ans);
    }

    #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("hull.in");
        //writer = new StreamWriter("hull.out");
#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;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solution
{
    const int MAXN = 50;
    const int MAX_INV = MAXN * MAXN;

    long Fun(int n, int mod)
    {
        var d = new long[MAX_INV];
        d[0] = 1;
        int max = 0;
        long ans = 0;
        for (int i = 1; i < n; i++)
        {
            var nd = new long[MAX_INV];
            int nmax = max;
            long sum = 0;
            for (int j = 0; j <= i; j++)
                for (int k = 0; k <= i; k++)
                {
                    for (int p = 0; p <= max; p++)
                    {
                        int o = p + j - k;
                        nmax = Math.Max(nmax, o);
                        if (o >= 0)
                        {
                            nd[o] = (nd[o] + d[p]) % mod;
                            if (j < k && o > 0)
                                sum = (sum + d[p]) % mod;
                        }
                        if (p == 0)
                            continue;
                        o = -p + j - k;
                        nmax = Math.Max(nmax, o);
                        if (o >= 0)
                        {
                            nd[o] = (nd[o] + d[p]) % mod;
                            if (j < k && o > 0)
                                sum = (sum + d[p]) % mod;
                        }
                    }
                }
            ans = ((i + 1) * ans + sum) % mod;
            max = nmax;
            d = nd;
        }

        return ans;
    }

    public void Solve()
    {
        int n = ReadInt();
        int mod = ReadInt();

        Write(Fun(n, mod));
    }

    #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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Library;

namespace Program
{
    public static class ProblemE
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = NN;
            var mod = NN;
            var dp = new long?[n + 1, n * (n - 1) / 2 + 1];
            Func<long, long, long> calc = null;
            calc = (pn, pk) =>
            {
                if (pn == 1 && pk == 0) return 1;
                if (pn < 0 || pk < 0 || pk > pn * (pn - 1) / 2) return 0;
                if (dp[pn, pk].HasValue) return dp[pn, pk].Value;
                dp[pn, pk] = (calc(pn, pk - 1) + calc(pn - 1, pk) + mod - calc(pn - 1, pk - pn)) % mod;
                return dp[pn, pk].Value;
            };
            var beforeAns = 0L;
            for (var N = 0; N <= n; ++N)
            {
                var ans = beforeAns * N % mod;
                for (var i = 0; i < N; ++i)
                {
                    for (var j = i + 1; j < N; ++j)
                    {
                        var sabun = j - i + 1;
                        var ten = (N - 1) * (N - 2) / 2;
                        var sum = 0L;
                        for (var k = 0; k + sabun <= ten; ++k)
                        {
                            sum = (sum + calc(N - 1, k)) % mod;
                            ans += sum * calc(N - 1, k + sabun) % mod;
                            ans %= mod;
                        }
                    }
                }
                beforeAns = ans;
            }
            Console.WriteLine(beforeAns);
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
        static bool Chmax<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) < 0) { lhs = rhs; return true; } return false; }
        static bool Chmin<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) > 0) { lhs = rhs; return true; } return false; }
        static void Fill<T>(this T[] array, T value) => array.AsSpan().Fill(value);
        static void Fill<T>(this T[,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0], array.Length).Fill(value);
        static void Fill<T>(this T[,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0], array.Length).Fill(value);
        static void Fill<T>(this T[,,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0, 0], array.Length).Fill(value);
    }
}
namespace Library {
    class LIB_FastIO
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[2048];
        int len, ptr;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        byte read()
        {
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 2048)) <= 0)
                {
                    return 0;
                }
            }
            return buf[ptr++];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = (ret << 3) + (ret << 1) + b - '0';
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIODebug() { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string Scan() => NextString();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override long Long() => long.Parse(NextString());
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override double Double() => double.Parse(NextString());
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Library;

namespace Program
{
    public static class ProblemE
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = NN;
            var mod = (ulong)NN;
            var br = new LIB_BarrettReduction(mod);
            var dp = new ulong?[n + 1, n * (n - 1) / 2 + 1];
            Func<long, long, ulong> calc = null;
            calc = (pn, pk) =>
            {
                if (pn == 1 && pk == 0) return 1;
                if (pn < 0 || pk < 0 || pk > pn * (pn - 1) / 2) return 0;
                if (dp[pn, pk].HasValue) return dp[pn, pk].Value;
                dp[pn, pk] = br.Reduce((calc(pn, pk - 1) + calc(pn - 1, pk) + mod - calc(pn - 1, pk - pn)));
                return dp[pn, pk].Value;
            };
            var beforeAns = 0UL;
            for (var N = 0L; N <= n; ++N)
            {
                var ans = br.Reduce(beforeAns * (ulong)N);
                for (var i = 0L; i < N; ++i)
                {
                    for (var j = i + 1; j < N; ++j)
                    {
                        var sabun = j - i + 1;
                        var ten = (N - 1) * (N - 2) / 2;
                        var sum = 0UL;
                        for (var k = 0L; k + sabun <= ten; ++k)
                        {
                            sum = br.Reduce(sum + calc(N - 1, k));
                            ans += br.Reduce(sum * calc(N - 1, k + sabun));
                            ans = br.Reduce(ans);
                        }
                    }
                }
                beforeAns = ans;
            }
            Console.WriteLine(beforeAns);
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
        static bool Chmax<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) < 0) { lhs = rhs; return true; } return false; }
        static bool Chmin<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) > 0) { lhs = rhs; return true; } return false; }
        static void Fill<T>(this T[] array, T value) => array.AsSpan().Fill(value);
        static void Fill<T>(this T[,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0], array.Length).Fill(value);
        static void Fill<T>(this T[,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0], array.Length).Fill(value);
        static void Fill<T>(this T[,,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0, 0], array.Length).Fill(value);
    }
}
namespace Library {
    class LIB_BarrettReduction
    {
        ulong MOD;
        ulong mh;
        ulong ml;
        const ulong ALL1_32 = (ulong)~0U;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_BarrettReduction(ulong mod)
        {
            MOD = mod;
            var m = ~0UL / MOD;
            unchecked { if (m * MOD + MOD == 0) ++m; }
            mh = m >> 32;
            ml = m & ALL1_32;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public ulong Reduce(ulong x)
        {
            var z = (x & ALL1_32) * ml;
            z = (x & ALL1_32) * mh + (x >> 32) * ml + (z >> 32);
            z = (x >> 32) * mh + (z >> 32);
            x -= z * MOD;
            return x < MOD ? x : x - MOD;
        }
    }
    class LIB_FastIO
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[2048];
        int len, ptr;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        byte read()
        {
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 2048)) <= 0)
                {
                    return 0;
                }
            }
            return buf[ptr++];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = (ret << 3) + (ret << 1) + b - '0';
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIODebug() { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string Scan() => NextString();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override long Long() => long.Parse(NextString());
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override double Double() => double.Parse(NextString());
    }
}