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

namespace AprilFools
{
    internal class Program
    {
        private const string TestIn = @"..\..\In\Text.in";
        private const string TestOut = @"..\..\In\Text.out";

        private static void Solve()
        {
            var input = ReadArray();
            var res = Convert.ToInt32(input[0]);

            var r2 = Convert.ToInt32(string.Join("", input[1].ToCharArray().Reverse()));

            Console.WriteLine(res+r2);
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(TestIn));
                Console.SetOut(new StreamWriter(TestOut));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.Out.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static List<int> ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            return input;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


/* Date: 14.04.2018 * Time: 21:45 */
// *

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;

*/

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

class Example
{
	public static void Main (string[] args)
	{
# if ( ! ONLINE_JUDGE )
		StreamReader sr = new StreamReader ("C:\\TRR\\2018\\Task\\07 Codeforces\\030\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2018\\Task\\07 Codeforces\\030\\A.OUT");
# endif

		NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;

		int n;

# if ( ONLINE_JUDGE )
		n = int.Parse (Console.ReadLine ());
# else
		n = int.Parse (sr.ReadLine ());
		sw.WriteLine ("n = " + n);
# endif

		string [] mapA = new string [n];

		for ( int i=0; i < n; i++ )
		{
# if ( ONLINE_JUDGE )
			mapA [i] = Console.ReadLine ();
# else
			mapA [i] = sr.ReadLine ();
# endif
		}

		string [] mapB = new string [n];

		for ( int i=0; i < n; i++ )
		{
# if ( ONLINE_JUDGE )
			mapB [i] = Console.ReadLine ();
# else
			mapB [i] = sr.ReadLine ();
# endif
		}

# if ( ! ONLINE_JUDGE )
		for ( int i=0; i < n; i++ )
			sw.WriteLine (mapA [i]);
		sw.WriteLine ();
		for ( int i=0; i < n; i++ )
			sw.WriteLine (mapB [i]);
		sw.WriteLine ();
# endif

		//
		bool ok1 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [i][j] != mapB [i][n-j-1] )
				{
					ok1 = false; break;
				}
			if ( ! ok1 )
				break;
		}
		//
		bool ok2 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [i][j] != mapB [n-1-i][j] )
				{
					ok2 = false; break;
				}
			if ( ! ok2 )
				break;
		}
		//
		bool ok3 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [i][j] != mapB [n-1-i][n-1-j] )
				{
					ok3 = false; break;
				}
			if ( ! ok3 )
				break;
		}
		//
		bool ok4 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [i][j] != mapB [j][n-1-i] )
				{
					ok4 = false; break;
				}
			if ( ! ok4 )
				break;
		}
		//
		bool ok5 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [j][n-1-i] != mapB [i][j] )
				{
					ok5 = false; break;
				}
			if ( ! ok5 )
				break;
		}
		//
		bool ok6 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [j][i] != mapB [i][j] )
				{
					ok6 = false; break;
				}
			if ( ! ok6 )
				break;
		}
		//
		bool ok7 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [n-1-j][n-1-i] != mapB [i][j] )
				{
					ok7 = false; break;
				}
			if ( ! ok7 )
				break;
		}
		//
		bool ok = ok1 || ok2 || ok3 || ok4 || ok5 || ok6 || ok7;
		//
# if ( ONLINE_JUDGE )
		if ( ok )
			Console.WriteLine ("Yes");
		else
			Console.WriteLine ("No");
# else
		if ( ok )
			sw.WriteLine ("Yes");
		else
			sw.WriteLine ("No");
		sw.Close ();
# endif

	}

}


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

namespace starwars
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;

            n = Convert.ToInt32 (Console.ReadLine());
            char[,] array1 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
               char[] temp =   Console.ReadLine().ToCharArray();
                for (int j = 0; j <= n - 1; j++)
                {
                    array1[i, j] = temp[j];
                }
            }
            char[,] array2 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                char[] temp = Console.ReadLine().ToCharArray();
                for (int j = 0; j <= n - 1; j++)
                {
                    array2[i, j] = temp[j];
                }
            }

                char[,] t90 = new char[n, n];
            for(int i = 0; i<=n-1;i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    t90[j, n - 1 - i] = array1[i, j];
            }

            char[,] t180 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    t180[j, n - 1 - i] = t90[i, j];
            }

            char[,] t270 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j<=n-1; j++)
                t270[j, n - 1 - i] = t180[i, j];
            }

            char[,] flippGorarray1 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGorarray1[n - 1 - i, j] = array1[i, j];
            }

            char[,] flippvertarray1 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvertarray1[i, n-1-j] = array1[i, j];
            }

            char[,] flippGort90 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGort90[n - 1 - i, j] = t90[i, j];
            }

            char[,] flippvert90 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvert90[i, n - 1 - j] = t90[i, j];
            }

            char[,] flippGort180 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGort180[n - 1 - i, j] = t180[i, j];
            }

            char[,] flippvert180 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvert180[i, n - 1 - j] = t180[i, j];
            }

            char[,] flippGorart270 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGorart270[n - 1 - i, j] = t270[i, j];
            }

            char[,] flippvert270 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvert270[i, n - 1 - j] = t270[i, j];
            }

            if (array2.ToString()== array1.ToString() || array2.ToString()== t90.ToString() || array2.ToString()== t180.ToString() ||
                array2.ToString()== t270.ToString() ||
                array2.ToString()== flippGorarray1.ToString() || array2.ToString()== flippvertarray1.ToString() ||
                array2.ToString() == flippGort90.ToString()||
                array2.ToString() == flippvert90.ToString()|| array2.ToString() == flippGort180.ToString() ||
                array2.ToString() == flippvert180.ToString()||
                array2.ToString() == flippGorart270.ToString() || array2.ToString() == flippvert270.ToString())
            {
                Console.WriteLine("Yes");
            }
            else Console.WriteLine("No");

        }

    }
}


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

class Program
{
    private static char[,] ReadMap(int n)
    {
        var ans = new char[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                ans[i, j] = ReadLetter();
        return ans;
    }

    private static char[,] Rotate(char[,] m, int n)
    {
        var newMap = new char[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                newMap[j, n - i - 1] = m[i, j];
            }

        return newMap;
    }

    private static bool IsSame(char[,] m1, char[,] m2, int n)
    {
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (m1[i, j] != m2[i, j]) return false;

        return true;
    }

    private static bool Compare(char[,] m1, char[,] m2, int n)
    {
        return IsSame(m1, Flip(m2, n, false, false), n) ||
            IsSame(m1, Flip(m2, n, true, false), n) ||
            IsSame(m1, Flip(m2, n, false, true), n) ||
            IsSame(m1, Flip(m2, n, true, true), n);
    }

    private static char[,] Flip(char[,] m, int n, bool byX, bool byY)
    {
        var newMap = new char[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                var newX = i;
                var newY = j;
                if (byX) newX = n - i - 1;
                if (byY) newY = n - j - 1;

                newMap[newX, newY] = m[i, j];
            }

        return newMap;
    }

    private static void Print(char[,] m, int n)
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                Console.Write(m[i, j] + " ");

            Console.WriteLine();
        }
        Console.WriteLine();
    }

    private static void Main(string[] args)
    {
        PushTestData(@"

2
XX
OO
XO
OX
");

        var n = RI();
        var m1 = ReadMap(n);
        var m2 = ReadMap(n);
        for (int i = 0; i < 5; i++)
        {/*
            Print(m1, n);
            Print(m2, n);
            Console.WriteLine();
            Console.WriteLine();*/
            if (Compare(m1, m2, n))
            {
                Console.WriteLine("Yes");
                return;
            }

            m2 = Rotate(m2, n);
        }

        Console.WriteLine("No");
    }

    private const int Mod = 1000000000 + 7;

    #region Data Read

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

    private static List<int>[] ReadTree(int n)
    {
        return ReadGraph(n, n - 1);
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < g.Length; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadWord()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z') || (ans == '*')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z') || (ans == '*'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char[] ReadStringLine()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans == 10 || ans == 13);

        List<char> s = new List<char>();

        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans != 10 && ans != 13 && ans != -1);

        return s.ToArray();
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadAnyOf(IEnumerable<char> allowed)
    {
        while (true)
        {
            char ans = (char)consoleReader.Read();
            if (allowed.Contains(ans))
                return ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(StringBuilder sb)
    {
        PushTestData(sb.ToString());
    }
    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
    #endregion
}


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

namespace starwars
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;

            n = Convert.ToInt32 (Console.ReadLine());
            char[,] array1 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
               char[] temp =   Console.ReadLine().ToCharArray();
                for (int j = 0; j <= n - 1; j++)
                {
                    array1[i, j] = temp[j];
                }
            }
            char[,] array2 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                char[] temp = Console.ReadLine().ToCharArray();
                for (int j = 0; j <= n - 1; j++)
                {
                    array2[i, j] = temp[j];
                }
            }

                char[,] t90 = new char[n, n];
            for(int i = 0; i<=n-1;i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    t90[j, n - 1 - i] = array1[i, j];
            }

            char[,] t180 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    t180[j, n - 1 - i] = t90[i, j];
            }

            char[,] t270 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j<=n-1; j++)
                t270[j, n - 1 - i] = t180[i, j];
            }

            char[,] flippGorarray1 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGorarray1[n - 1 - i, j] = array1[i, j];
            }

            char[,] flippvertarray1 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvertarray1[i, n-1-j] = array1[i, j];
            }

            char[,] flippGort90 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGort90[n - 1 - i, j] = t90[i, j];
            }

            char[,] flippvert90 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvert90[i, n - 1 - j] = t90[i, j];
            }

            char[,] flippGort180 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGort180[n - 1 - i, j] = t180[i, j];
            }

            char[,] flippvert180 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvert180[i, n - 1 - j] = t180[i, j];
            }

            char[,] flippGorart270 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGorart270[n - 1 - i, j] = t270[i, j];
            }

            char[,] flippvert270 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvert270[i, n - 1 - j] = t270[i, j];
            }

            if (Equal(array2, array1, n) ||
                Equal(array2, t90, n) ||
                Equal(array2, t180, n) ||
                Equal(array2, t270, n) ||
                Equal(array2, flippGorarray1, n) ||
                Equal(array2, flippvertarray1, n) ||
                Equal(array2, flippGort90, n) ||
                Equal(array2, flippvert90, n) ||
                Equal(array2, flippGort180, n) ||
                Equal(array2, flippvert180, n) ||
                Equal(array2, flippGorart270, n) ||
                Equal(array2, flippvert270, n) )
            {
                Console.WriteLine("Yes");
            }
            else Console.WriteLine("No");

        }
         static bool Equal(char[,]ar1, char[,] ar2, int n)
        {
            for (int i = 0; i < n;i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (ar1[i, j] != ar2[i, j])
                    {
                        return false;

                    }
                }

            }
            return true;
        }

    }
}


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

namespace Codeforces
{

    class Program
    {
        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        public static readonly int oo = Convert.ToInt32(1e9);
        public static readonly long OO = Convert.ToInt64(1e18);

        static void Main(string[] args)
        {
            String[] firstLine = Console.ReadLine().Split(' ');
            int n = int.Parse(firstLine[0]);
            int m = int.Parse(firstLine[1]);
            int k = Math.Min(n, int.Parse(firstLine[2]));
            if (k % 2 == 0)
            {
                if (n == 4)
                {
                    Console.WriteLine(m * m);
                } else
                {
                    Console.WriteLine(m);
                }
            } else
            {
                Console.WriteLine(m * m);
            }

        }

    }

}


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

public class E
{
    public partial class Myon
    {

        static void Main()
        {
            E p = new E();
            p.solve();
        }

    }

    const int mod = (int)(1e9 + 7 + 1e-9);
    public void solve()
    {
        int[] tmp = intSplit(' ');
        int n = tmp[0];
        int m = tmp[1];
        int k = tmp[2];

        if (k == 1 || k > n)
            Console.WriteLine(ModPow(m, n, mod));
        else if (k == n)
            Console.WriteLine(ModPow(m, (n + 1) >> 1, mod));
        else if ((k & 1) == 1)
            Console.WriteLine(m);
        else
            Console.WriteLine((long)m * m % mod);
    }

    /// <summary>
    /// varified by CodeForces 104 DIV2 E LuckySubsequence
    /// %mod における a の n 乗を求める
    /// O(log n )
    /// </summary>
    /// <param name="a">冪乗される値</param>
    /// <param name="n">冪</param>
    /// <returns>a^n</returns>
    public static long ModPow(long a, long n, int mod)
    {
        long res = 1;
        long tmp = a;
        for (; n > 0; n >>= 1)
        {
            if ((n & 1) == 1)
                res = res * tmp % mod;
            tmp = tmp * tmp % mod;
        }
        return res;
    }//ModPow

    string stringRead()
    { return Console.ReadLine(); }

    int intRead()
    { return int.Parse(Console.ReadLine()); }

    long longRead()
    { return long.Parse(Console.ReadLine()); }

    string[] stringSplit(char a)
    { return Console.ReadLine().Split(a); }

    int[] intSplit(char a)
    { return Array.ConvertAll<string, int>(Console.ReadLine().Split(a), int.Parse); }

    long[] longSplit(char a)
    { return Array.ConvertAll<string, long>(Console.ReadLine().Split(a), long.Parse); }

    void write(string str)
    {
        Console.WriteLine(str);
    }
}


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

namespace Codeforces
{
    class C
    {
        private static bool s_time = false;

        public static IList<int[]> Factors(int n)
        {
            List<int[]> ret = new List<int[]>();
            for (int p = 2; p * p <= n; ++p)
            {
                if (n % p == 0)
                {
                    n /= p;
                    int[] factor = new int[] { p, 1 };
                    ret.Add(factor);
                    while (n % p == 0)
                    {
                        n /= p;
                        factor[1]++;
                    }
                }
            }
            if (n > 1) ret[ret.Count - 1][1]++;
            return ret;
        }

        private static object Go()
        {
            int N = GetInt();

            IList<int[]> factors = Factors(N);
            if (factors.Count >= 2)
            {
                if (N == factors[0][0] * factors[1][0]) return 2;
                Wl("1");
                return factors[0][0] * factors[1][0];
            }
            if (factors.Count == 0 || factors[0][1] < 2)
            {
                Wl("1");
                return 0;
            }
            if (factors[0][1] == 2) return 2;
            Wl(1);
            return factors[0][0] * factors[0][0];
        }

        #region Template

        public static void Main(string[] args)
        {
            DateTime start = DateTime.Now;
            object output = Go();
            TimeSpan duration = DateTime.Now.Subtract(start);
            if (output != null)
                Wl<string>(output.ToString());
            if (s_time)
                Wl(duration);
        }

        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 void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

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

        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;

public class BlackWhiteMagic {

    public static void Main()
    {
        string[] ss = Console.ReadLine().Split();

        int n = int.Parse(ss[0]);
        int m = int.Parse(ss[1]);
        int k = int.Parse(ss[2]);

        long res = 1;

        if (k>n)
        {
            for (int i = 0; i < n; i++) res = (res * m) % 1000000007;
        }
        else if (k == n)
        {
            for (int i = 0; i < (n + 1) / 2; i++) res = (res * m) % 1000000007;
        }
        else
        {
            if (k%2 == 0) res = m;
            else res = m > 1 ? m*(m - 1) : 1;
        }

        Console.WriteLine(res);
    }
}


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

namespace Codeforces
{
    class B
    {
        private static bool s_time = false;

        private static long mod = 1000000007;
        private static long pow(long a, long b)
        {
            long ret = 1;
            for (int i = 0; i < b; i++)
            {
                ret = (ret * a) % mod;
            }
            return ret;
        }

        private static object Go()
        {
            int ret = 1;

            int n = GetInt();
            int m = GetInt();
            int k = GetInt();

            if (n < k) return 0;
            if (k == 1)
                return pow(m, n);
            if (n == k)
            {
                return pow(m, (n + 1) / 2);
            }
            if (k == 2)
                return m;
            if (k == 3)
                return (m + m * (m - 1)) % mod;
            if (k % 2 == 0)
                return m;
            return (m + m * (m - 1)) % mod;
        }

        #region Template

        public static void Main(string[] args)
        {
            DateTime start = DateTime.Now;
            object output = Go();
            TimeSpan duration = DateTime.Now.Subtract(start);
            if (output != null)
                Wl<string>(output.ToString());
            if (s_time)
                Wl(duration);
        }

        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 void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

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

        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;

public class BlackWhiteMagic {

    public static void Main()
    {
        string[] ss = Console.ReadLine().Split();

        int n = int.Parse(ss[0]);
        int m = int.Parse(ss[1]);
        int k = int.Parse(ss[2]);

        long res = 1;

        if (k>n)
        {
            for (int i = 0; i < n; i++) res = (res * m) % 1000000007;
        }
        else if (k == n)
        {
            for (int i = 0; i < (n + 1) / 2; i++) res = (res * m) % 1000000007;
        }
        else
        {
            if (k%2 == 0) res = m;
            else res = m*m;
        }

        Console.WriteLine(res);
    }
}


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

namespace Codeforces
{
    class B
    {
        private static bool s_time = false;

        private static long mod = 1000000007;
        private static long pow(long a, long b)
        {
            long ret = 1;
            for (int i = 0; i < b; i++)
            {
                ret = (ret * a) % mod;
            }
            return ret;
        }

        private static object Go()
        {
            int ret = 1;

            int n = GetInt();
            int m = GetInt();
            int k = GetInt();

            if (n < k) return 0;
            if (n == k)
            {
                return pow(m, (n + 1) / 2);
            }
            if (k == 1)
                return pow(m, n);
            if (k == 2)
                return m;
            if (k == 3)
                return (m + m * (m - 1)) % mod;
            if (k % 2 == 0)
                return m;
            return (m + m * (m - 1)) % mod;
        }

        #region Template

        public static void Main(string[] args)
        {
            DateTime start = DateTime.Now;
            object output = Go();
            TimeSpan duration = DateTime.Now.Subtract(start);
            if (output != null)
                Wl<string>(output.ToString());
            if (s_time)
                Wl(duration);
        }

        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 void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

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

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

namespace Quantity_of_Strings
{
    internal class Program
    {
        private const int mod = 1000000007;
        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)
        {
            int n = Next();
            int m = Next();
            int k = Next();

            if (k == 1)
            {
                writer.WriteLine(Pow(m, n));
            }
            else if (k == n)
            {
                writer.WriteLine(Pow(m, (n + 1)/2));
            }
            else if (k > n)
            {
                writer.WriteLine("0");
            }
            else
            {
                writer.WriteLine(m);
            }

            writer.Flush();
        }

        private static long Pow(long a, int k)
        {
            long r = 1;
            while (k > 0)
            {
                if ((k & 1) == 1)
                {
                    r = (r*a)%mod;
                }
                a = (a*a)%mod;
                k >>= 1;
            }
            return r;
        }

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


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

namespace Quantity_of_Strings
{
    internal class Program
    {
        private const int mod = 1000000007;
        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)
        {
            int n = Next();
            int m = Next();
            int k = Next();

            if (k == 1)
            {
                writer.WriteLine(Pow(m, n));
            }
            else if (k == n)
            {
                writer.WriteLine(Pow(m, (n + 1)/2));
            }
            else if (k > n)
            {
                writer.WriteLine(Pow(m, n));
            }
            else
            {
                writer.WriteLine(m);
            }

            writer.Flush();
        }

        private static long Pow(long a, int k)
        {
            long r = 1;
            while (k > 0)
            {
                if ((k & 1) == 1)
                {
                    r = (r*a)%mod;
                }
                a = (a*a)%mod;
                k >>= 1;
            }
            return r;
        }

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


using System;

public class BlackWhiteMagic {

    public static void Main()
    {
        string[] ss = Console.ReadLine().Split();

        int n = int.Parse(ss[0]);
        int m = int.Parse(ss[1]);
        int k = int.Parse(ss[2]);

        long res = 0;
        if (k % 2 == 0) res = m;
        else res = m > 1 ? m*(m - 1) : 1;

        Console.WriteLine(res);
    }
}


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

namespace Main
{
    internal class Program
    {
        public static void Main(String[] args)
        {
//            Console.SetIn(new StreamReader("c:\\a.txt"));

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

            Console.WriteLine(TotalCombination(int.Parse(tok[0]), int.Parse(tok[1]), int.Parse(tok[2])));
        }

        private static long TotalCombination(int n, int m, int k)
        {
            const int modVal = 1000000007;

            if (k == 1)
                return ModPow(m, n, modVal);

            if (k == n)
                return ModPow(m, (n + 1) >> 1, modVal);

            if (k % 2 == 1)
                return (m*m)%modVal;

            return m;
        }

        private static long ModPow(int b, int p, int modVal)
        {
            if (p == 0)
                return 1;

            long temp = ModPow(b, p >> 1, modVal);

            temp = (temp*temp)%modVal;

            if (p % 2 == 0)
                return temp;

            return (temp*b)%modVal;
        }
    }
}


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

namespace Codeforces
{
    class B
    {
        private static bool s_time = false;

        private static long mod = 1000000007;
        private static long pow(long a, long b)
        {
            long ret = 1;
            for (int i = 0; i < b; i++)
            {
                ret = (ret * a) % mod;
            }
            return ret;
        }

        private static object Go()
        {
            int ret = 1;

            int n = GetInt();
            int m = GetInt();
            int k = GetInt();

            if (n < k) return 0;
            if (k == 1)
                return pow(m, n);
            if (k == 2)
                return m;
            if (k == 3)
                return (m + m * (m - 1)) % mod;
            if (n == k)
            {
                return pow(m, (n + 1) / 2);
            }
            if (k % 2 == 0)
                return m;
            return (m + m * (m - 1)) % mod;
        }

        #region Template

        public static void Main(string[] args)
        {
            DateTime start = DateTime.Now;
            object output = Go();
            TimeSpan duration = DateTime.Now.Subtract(start);
            if (output != null)
                Wl<string>(output.ToString());
            if (s_time)
                Wl(duration);
        }

        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 void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

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

        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.IO;

namespace AcmSolution4
{
    class Program
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader("../../../a.txt"));
#endif
            int[] a = GetInts();

            long n = a[0], m = a[1], k = a[2];

            long ans = 1;
            long t = 1000000007;

            if (n == k || k == 1)
            {
                long max = k == 1 ? n : (n/2 + n%2);
                for (int i = 1; i <= max; ++ i)
                {
                    ans *= m;
                    if (ans > t) ans %= t;
                }
            }
            else if (n < k)
                ans = 0;
            else if (m == 1)
                ans = 1;
            else
            {
                if (k >= 4)
                    ans = m;
                else if (k == 3)
                    ans = m * m;
                else if (k == 2)
                    ans = m;
            }

            WL(ans);
        }

        static int GetInt()
        {
            return int.Parse(GetStr());
        }

        static int GetInt(string s)
        {
            return int.Parse(s);
        }

        static int[] GetInts()
        {
            string[] ss = GetStrs();
            int[] nums = new int[ss.Length];

            int i = 0;
            foreach (string s in ss)
                nums[i++] = GetInt(s);

            return nums;
        }

        static string[] GetStrs()
        {
            return Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        static long GetLong()
        {
            return long.Parse(GetStr());
        }

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

        static void WL<T>(T s)
        {
            Console.WriteLine(s);
        }

        static void W<T>(T s)
        {
            Console.Write(s);
        }
    }

    internal class Pair
    {
        public int number;
        public int value;
        public Pair(int i, int j)
        {
            number = i;
            value = j;
        }
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static int[] ReadIntArray()
        {
            var input = ReadArray();
            var res = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                res[i] = ReadNextInt(input, i);
            }
            return res;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        private static List<long> divs;
        private static void Main()
        {
            var MOD = 1000000007;
            var input = ReadIntArray();
            var n = input[0];
            var m = input[1];
            var k = input[2];
            if(m == 1)
            {
                Console.WriteLine(1);
                return;
            }
            long res = 1;
            if(n < k)
            {
                for (int i = 0; i < n; i++)
                {
                    res *= m;
                    res %= MOD;
                }
                Console.WriteLine(res);
                return;
            }
            if(n == k)
            {
                for (int i = 0; i < n / 2 + (n %2); i++)
                {
                    res *= m;
                    res %= MOD;
                }
                Console.WriteLine(res);
                return;
            }
            if(k % 2 == 0)
            {
                Console.WriteLine(m);
                return;
            }
            Console.WriteLine(m*m);
        }
    }
}


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

namespace AcmSolution4
{
    class Program
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader("../../../a.txt"));
#endif
            int[] a = GetInts();

            long n = a[0], m = a[1], k = a[2];

            long ans = 1;
            long t = 1000000007;

            if (n <= k || k == 1)
            {
                long max = k == 1 ? n : (n/2 + n%2);
                for (int i = 1; i <= max; ++ i)
                {
                    ans *= m;
                    if (ans > t) ans %= t;
                }
            }
            else if (n < k)
                ans = 0;
            else if (m == 1)
                ans = 1;
            else
            {
                if (k >= 4)
                    ans = k % 2 == 0 ? m : m * m;
                else if (k == 3)
                    ans = m * m;
                else if (k == 2)
                    ans = m;

            }
            WL(ans);
        }

        static int GetInt()
        {
            return int.Parse(GetStr());
        }

        static int GetInt(string s)
        {
            return int.Parse(s);
        }

        static int[] GetInts()
        {
            string[] ss = GetStrs();
            int[] nums = new int[ss.Length];

            int i = 0;
            foreach (string s in ss)
                nums[i++] = GetInt(s);

            return nums;
        }

        static string[] GetStrs()
        {
            return Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        static long GetLong()
        {
            return long.Parse(GetStr());
        }

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

        static void WL<T>(T s)
        {
            Console.WriteLine(s);
        }

        static void W<T>(T s)
        {
            Console.Write(s);
        }
    }

    internal class Pair
    {
        public int number;
        public int value;
        public Pair(int i, int j)
        {
            number = i;
            value = j;
        }
    }
}


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

public class D
{
    public partial class Myon
    {

        static void Main()
        {
            D p = new D();
            p.solve();
        }

    }

    const int mod = 1000000007;
    public void solve()
    {
        int[] tmp = intSplit(' ');
        int n = tmp[0];
        int m = tmp[1];
        int k = tmp[2];

        if (k > n)
        {
            Console.WriteLine(0);
            return;
        }

        if (k == 1)
        {
            Console.WriteLine(ModPow(m,n,mod));
            return;
        }

        if (n == k)
        {
            Console.WriteLine(ModPow(m,n+1>>1,mod));
            return;
        }

        if ((k&1) == 0)
        {
            Console.WriteLine(m);
            return;
        }

        if ((k & 1) == 1)
        {
            Console.WriteLine((long)m*m%mod);
            return;
        }

    }

    /// <summary>
    /// varified by CodeForces 104 DIV2 E LuckySubsequence
    /// %mod における a の n 乗を求める
    /// O(log n )
    /// </summary>
    /// <param name="a">冪乗される値</param>
    /// <param name="n">冪</param>
    /// <returns>a^n</returns>
    public static long ModPow(long a, long n, int mod)
    {
        long res = 1;
        long tmp = a;
        for (; n > 0; n >>= 1)
        {
            if ((n & 1) == 1)
                res = res * tmp % mod;
            tmp = tmp * tmp % mod;
        }
        return res;
    }//ModPow

    string stringRead()
    { return Console.ReadLine(); }

    int intRead()
    { return int.Parse(Console.ReadLine()); }

    long longRead()
    { return long.Parse(Console.ReadLine()); }

    string[] stringSplit(char a)
    { return Console.ReadLine().Split(a); }

    int[] intSplit(char a)
    { return Array.ConvertAll<string, int>(Console.ReadLine().Split(a), int.Parse); }

    long[] longSplit(char a)
    { return Array.ConvertAll<string, long>(Console.ReadLine().Split(a), long.Parse); }

    void write(string str)
    {
        Console.WriteLine(str);
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static int[] ReadIntArray()
        {
            var input = ReadArray();
            var res = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                res[i] = ReadNextInt(input, i);
            }
            return res;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        private static List<long> divs;
        private static void Main()
        {
            var MOD = 1000000007;
            var input = ReadIntArray();
            var n = input[0];
            var m = input[1];
            var k = input[2];
            if(m == 1)
            {
                Console.WriteLine(1);
                return;
            }
            long res = 1;
            if(n < k || k==1)
            {
                for (int i = 0; i < n; i++)
                {
                    res *= m;
                    res %= MOD;
                }
                Console.WriteLine(res);
                return;
            }
            if(n == k)
            {
                for (int i = 0; i < n / 2 + (n %2); i++)
                {
                    res *= m;
                    res %= MOD;
                }
                Console.WriteLine(res);
                return;
            }
            if(k % 2 == 0)
            {
                Console.WriteLine(m);
                return;
            }
            Console.WriteLine(m*m);
        }
    }
}


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

public class E
{
    public partial class Myon
    {

        static void Main()
        {
            E p = new E();
            p.solve();
        }

    }

    const int mod = (int)(1e9 + 7 + 1e-9);
    public void solve()
    {
        int[] tmp = intSplit(' ');
        int n = tmp[0];
        int m = tmp[1];
        int k = tmp[2];

        if (k == 1 || k > n)
            Console.WriteLine(ModPow(m, n, mod));
        else if (k == n)
            Console.WriteLine(ModPow(m, (n + 1) >> 1, mod));
        else if ((k & 1) == 1)
            Console.WriteLine((long)m * m % mod);
        else
            Console.WriteLine(m);
    }

    /// <summary>
    /// varified by CodeForces 104 DIV2 E LuckySubsequence
    /// %mod における a の n 乗を求める
    /// O(log n )
    /// </summary>
    /// <param name="a">冪乗される値</param>
    /// <param name="n">冪</param>
    /// <returns>a^n</returns>
    public static long ModPow(long a, long n, int mod)
    {
        long res = 1;
        long tmp = a;
        for (; n > 0; n >>= 1)
        {
            if ((n & 1) == 1)
                res = res * tmp % mod;
            tmp = tmp * tmp % mod;
        }
        return res;
    }//ModPow

    string stringRead()
    { return Console.ReadLine(); }

    int intRead()
    { return int.Parse(Console.ReadLine()); }

    long longRead()
    { return long.Parse(Console.ReadLine()); }

    string[] stringSplit(char a)
    { return Console.ReadLine().Split(a); }

    int[] intSplit(char a)
    { return Array.ConvertAll<string, int>(Console.ReadLine().Split(a), int.Parse); }

    long[] longSplit(char a)
    { return Array.ConvertAll<string, long>(Console.ReadLine().Split(a), long.Parse); }

    void write(string str)
    {
        Console.WriteLine(str);
    }
}


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

namespace Main
{
    internal class Program
    {
        public static void Main(String[] args)
        {
//            Console.SetIn(new StreamReader("c:\\a.txt"));

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

            Console.WriteLine(TotalCombination(int.Parse(tok[0]), int.Parse(tok[1]), int.Parse(tok[2])));
        }

        private static long TotalCombination(int n, int m, int k)
        {
            const int modVal = 1000000007;

            if (k == 1 || k > n)
                return ModPow(m, n, modVal);

            if (k == n)
                return ModPow(m, (n + 1) >> 1, modVal);

            if (k % 2 == 1)
                return (m*m)%modVal;

            return m;
        }

        private static long ModPow(int b, int p, int modVal)
        {
            if (p == 0)
                return 1;

            long temp = ModPow(b, p >> 1, modVal);

            temp = (temp*temp)%modVal;

            if (p % 2 == 0)
                return temp;

            return (temp*b)%modVal;
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            const Int64 mod = 1000000007;
            string[] t = Console.ReadLine().Split(
                new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            int n = int.Parse(t[0]);
            int m = int.Parse(t[1]);
            int k = int.Parse(t[2]);
            if (n == k)
            {
                Int64 res = 1;
                for (int i = 0; i < n / 2 + n % 2; i++)
                    res = (res * m) % mod;
                Console.WriteLine(res);
                return;
            }
            if ((k > n) || (k == 1))
            {
                Int64 res = 1;
                for (int i = 0; i < n; i++)
                    res = (res * m) % mod;
                Console.WriteLine(res);
                return;
            }
            if (k % 2 == 0)
            {
                Console.WriteLine(m);
                return;
            }
            Console.WriteLine(m * m);
        }
    }
}


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

namespace Quantity_of_Strings
{
    internal class Program
    {
        private const int mod = 1000000007;
        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)
        {
            int n = Next();
            int m = Next();
            int k = Next();

            if (k == 1)
            {
                writer.WriteLine(Pow(m, n));
            }
            else if (k == n)
            {
                writer.WriteLine(Pow(m, (n + 1)/2));
            }
            else if (k > n)
            {
                writer.WriteLine(Pow(m, n));
            }
            else
            {
                if (k%2 == 1)
                    writer.WriteLine(m*m);
                else
                    writer.WriteLine(m);
            }

            writer.Flush();
        }

        private static long Pow(long a, int k)
        {
            long r = 1;
            while (k > 0)
            {
                if ((k & 1) == 1)
                {
                    r = (r*a)%mod;
                }
                a = (a*a)%mod;
                k >>= 1;
            }
            return r;
        }

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


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

public class CasketOfStar
{

    public static void ans(int m, int n)
    {
        long k = 1;
        for (int i = 0; i < n; i++) {
            k *= m ;
            k %= 1000000007;
        }
        Console.WriteLine(k);
    }

public static void Main(string[] args)
    {
        int [] arr = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
        if(arr[2] == 1 || arr[2] > arr[0])
        {
            //m^n
            ans(arr[1], arr[0]);
        }
        else if(arr[2] == arr[0])
        {
            //m^(n+1)/2
            ans(arr[1], (arr[0]+1)/2);
        }
        else if(arr[2] % 2 ==0)
        {

            ans(arr[1], 1);
        }
        else
        {
            ans(arr[1], 2);

        }

    }

}


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

public class D
{
    public partial class Myon
    {

        static void Main()
        {
            D p = new D();
            p.solve();
        }

    }

    const int mod = 1000000007;
    public void solve()
    {
        int[] tmp = intSplit(' ');
        int n = tmp[0];
        int m = tmp[1];
        int k = tmp[2];

        if (k>n||k == 1)
        {
            Console.WriteLine(ModPow(m,n,mod));
            return;
        }

        if (n == k)
        {
            Console.WriteLine(ModPow(m,n+1>>1,mod));
            return;
        }

        if ((k&1) == 0)
        {
            Console.WriteLine(m);
            return;
        }

        if ((k & 1) == 1)
        {
            Console.WriteLine((long)m*m%mod);
            return;
        }

    }

    /// <summary>
    /// varified by CodeForces 104 DIV2 E LuckySubsequence
    /// %mod における a の n 乗を求める
    /// O(log n )
    /// </summary>
    /// <param name="a">冪乗される値</param>
    /// <param name="n">冪</param>
    /// <returns>a^n</returns>
    public static long ModPow(long a, long n, int mod)
    {
        long res = 1;
        long tmp = a;
        for (; n > 0; n >>= 1)
        {
            if ((n & 1) == 1)
                res = res * tmp % mod;
            tmp = tmp * tmp % mod;
        }
        return res;
    }//ModPow

    string stringRead()
    { return Console.ReadLine(); }

    int intRead()
    { return int.Parse(Console.ReadLine()); }

    long longRead()
    { return long.Parse(Console.ReadLine()); }

    string[] stringSplit(char a)
    { return Console.ReadLine().Split(a); }

    int[] intSplit(char a)
    { return Array.ConvertAll<string, int>(Console.ReadLine().Split(a), int.Parse); }

    long[] longSplit(char a)
    { return Array.ConvertAll<string, long>(Console.ReadLine().Split(a), long.Parse); }

    void write(string str)
    {
        Console.WriteLine(str);
    }
}


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

namespace Codeforces
{
    class Program
    {

        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        public static readonly int oo = Convert.ToInt32(1e9);
        public static readonly long OO = Convert.ToInt64(1e18);

        static void Main(string[] args)
        {
            String[] data = Console.ReadLine().Split(' ');
            int LengthOfWord = int.Parse(data[0]);
            int alphabetSize = int.Parse(data[1]);
            int requiredPalindromLength = int.Parse(data[2]);
            if (requiredPalindromLength > LengthOfWord)
            {
                Console.WriteLine(ModPow(alphabetSize, LengthOfWord));
                return;
            }

            Dsu dsu = new Dsu(LengthOfWord + 1);
            if (requiredPalindromLength % 2 == 0)
            {

                for (int center = 1; center <= LengthOfWord; center++)
                {
                    if (Math.Min(center, LengthOfWord - center) >= requiredPalindromLength / 2)
                    {
                        for (int count = 0; count < requiredPalindromLength / 2; count++)
                        {
                            dsu.Unite(center - count, center + count + 1);
                        }
                    }
                }
            } else
            {
                for (int center = 1; center <= LengthOfWord; center++)
                {
                    if (Math.Min(center - 1, LengthOfWord - center) >= requiredPalindromLength / 2)
                    {
                        dsu.Unite(center, center);
                        for (int count = 1; count <= requiredPalindromLength / 2; count++)
                        {
                            dsu.Unite(center - count, center + count);
                        }
                    }
                }
            }

            Console.WriteLine(ModPow(alphabetSize, dsu.Rank.Count(s => s > 0) - 1));
        }

        static long ModPow(long num, long exponent)
        {
            if (exponent == 0) return 1;
            long m = ModPow(num, exponent / 2);
            return exponent % 2 == 0 ? m * m % MOD : m * m % MOD * num % MOD;
        }

        struct Dsu
        {
            public int Vertices { get; set; }
            public int ConnectedComponent { get; set; }
            public int[] ParentOf { get; set; }
            public int[] Rank { get; set; }

            public Dsu(int vertices)
            {
                Vertices = vertices;
                ConnectedComponent = vertices;
                ParentOf = Enumerable.Range(0, vertices).ToArray();
                Rank = Enumerable.Range(0, vertices).Select(v => v = 1).ToArray();
            }

            public bool IsConnected(int from, int to)
            {
                return GetAncestor(from) == GetAncestor(to);
            }

            public int GetAncestor(int descended)
            {
                while (descended != ParentOf[descended]) descended = ParentOf[descended];
                return descended;
            }

            public void Unite(int from, int to)
            {
                int ancestorOfFrom = GetAncestor(from);
                int ancestorOfTo = GetAncestor(to);
                if (ancestorOfFrom == ancestorOfTo) return;
                ConnectedComponent--;
                if (Rank[ancestorOfFrom] > Rank[ancestorOfTo])
                {
                    ParentOf[ancestorOfTo] = ParentOf[ancestorOfFrom];
                    Rank[ancestorOfFrom] += Rank[ancestorOfTo];
                    Rank[ancestorOfTo] = 0;
                } else
                {
                    ParentOf[ancestorOfFrom] = ParentOf[ancestorOfTo];
                    Rank[ancestorOfTo] += Rank[ancestorOfFrom];
                    Rank[ancestorOfFrom] = 0;
                }
            }

        }

    }

}


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

namespace Codeforces
{
    class B
    {
        private static bool s_time = false;

        private static long mod = 1000000007;
        private static long pow(long a, long b)
        {
            long ret = 1;
            for (int i = 0; i < b; i++)
            {
                ret = (ret * a) % mod;
            }
            return ret;
        }

        private static object Go()
        {
            int ret = 1;

            int n = GetInt();
            int m = GetInt();
            int k = GetInt();

            if (n < k || k == 1)
                return pow(m, n);
            if (n == k)
                return pow(m, (n + 1) / 2);
            if (k % 2 == 0)
                return m;

            return (m + m * (m - 1)) % mod;
        }

        #region Template

        public static void Main(string[] args)
        {
            DateTime start = DateTime.Now;
            object output = Go();
            TimeSpan duration = DateTime.Now.Subtract(start);
            if (output != null)
                Wl<string>(output.ToString());
            if (s_time)
                Wl(duration);
        }

        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 void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

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

        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.IO;

namespace AcmSolution4
{
    class Program
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader("../../../a.txt"));
#endif
            int[] a = GetInts();

            long n = a[0], m = a[1], k = a[2];

            long ans = 1;
            long t = 1000000007;

            if (n <= k || k == 1)
            {
                long max = (k == 1 || k > n) ? n : (n/2 + n%2);
                for (int i = 1; i <= max; ++ i)
                {
                    ans *= m;
                    if (ans > t) ans %= t;
                }
            }
            else if (m == 1)
                ans = 1;
            else
            {
                if (k >= 4)
                    ans = k % 2 == 0 ? m : m * m;
                else if (k == 3)
                    ans = m * m;
                else if (k == 2)
                    ans = m;

            }
            WL(ans);
        }

        static int GetInt()
        {
            return int.Parse(GetStr());
        }

        static int GetInt(string s)
        {
            return int.Parse(s);
        }

        static int[] GetInts()
        {
            string[] ss = GetStrs();
            int[] nums = new int[ss.Length];

            int i = 0;
            foreach (string s in ss)
                nums[i++] = GetInt(s);

            return nums;
        }

        static string[] GetStrs()
        {
            return Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        static long GetLong()
        {
            return long.Parse(GetStr());
        }

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

        static void WL<T>(T s)
        {
            Console.WriteLine(s);
        }

        static void W<T>(T s)
        {
            Console.Write(s);
        }
    }

    internal class Pair
    {
        public int number;
        public int value;
        public Pair(int i, int j)
        {
            number = i;
            value = j;
        }
    }
}


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

namespace Codeforces
{
    class B
    {
        private static bool s_time = false;

        private static long mod = 1000000007;
        private static long pow(long a, long b)
        {
            long ret = 1;
            for (int i = 0; i < b; i++)
            {
                ret = (ret * a) % mod;
            }
            return ret;
        }

        private static object Go()
        {
            int ret = 1;

            int n = GetInt();
            int m = GetInt();
            int k = GetInt();

            if (n < k)
                return pow(m, n);
            if (n == k)
            {
                return pow(m, (n + 1) / 2);
            }
            if (k % 2 == 0)
                return m;

            return (m + m * (m - 1)) % mod;
        }

        #region Template

        public static void Main(string[] args)
        {
            DateTime start = DateTime.Now;
            object output = Go();
            TimeSpan duration = DateTime.Now.Subtract(start);
            if (output != null)
                Wl<string>(output.ToString());
            if (s_time)
                Wl(duration);
        }

        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 void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

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

        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.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;

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

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

        Write(ans);
    }

    #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 ans = 0L;
            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;
                    }
                }
            }
            Console.WriteLine(ans);
        }
        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());
    }
}