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

namespace run
{
    class Program
    {
        private static int Swap(ref int a, ref int b)
        {
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            return 0;
        }

        private static int gcd(int a, int b)
        {
            Swap(ref a, ref b);

            while (a % b != 0)
            {
                a %= b;
                Swap(ref a, ref b);
            }

            return b;

        }

        private const long MOD = 1000000009;

        private static void Main(string[] args)
        {

            var nstr = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            int n = nstr[0], m = nstr[1], k = nstr[2];
            int l = n - m;
            long result = 0;
            long good = 0;
            int count = k * l;

            int num = (n - count) / k;

            //long kjk = BinPow(2, num + 1);

            long SUMM = k * 2 * (BinPow(2, num) - 1) % MOD;

            result += SUMM;

            /*for (int i = k; i <= n - count; i += k)
            {
                result += k;
                good = k;
                if (good == k)
                {
                    result <<= 1;
                    good = 0;
                    if (result >= MOD) result -= MOD;
                }
            }*/

            result += ((n - count) % k);

            result += count - l;
            if (result >= MOD) result -= MOD;

            Console.WriteLine(result);

        }

        private static long BinPow(int a, int degr)
        {
            if (degr == 0) return 1;
            if ((degr & 1) == 1) return a * (BinPow(a, degr - 1) % MOD);
            else
            {
                long value = BinPow(a, degr >> 1) % MOD;
                return value * value % MOD;
            }
        }
    }
}


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

namespace run
{
    class Program
    {
        private static int Swap(ref int a, ref int b)
        {
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            return 0;
        }

        private static int gcd(int a, int b)
        {
            Swap(ref a, ref b);

            while (a % b != 0)
            {
                a %= b;
                Swap(ref a, ref b);
            }

            return b;

        }

        private const long MOD = 1000000009;

        private static void Main(string[] args)
        {

            var nstr = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            int n = nstr[0], m = nstr[1], k = nstr[2];
            int l = n - m;
            long result = 0;
            long good = 0;
            int count = k * l;
            if (n - count == 0)
            {
                Console.WriteLine(0);
                return;
            }
            int num = (n - count) / k;

            //long kjk = BinPow(2, num + 1);

            long SUMM = k * 2 * (BinPow(2, num) - 1) % MOD;

            result += SUMM;

            /*for (int i = k; i <= n - count; i += k)
            {
                result += k;
                good = k;
                if (good == k)
                {
                    result <<= 1;
                    good = 0;
                    if (result >= MOD) result -= MOD;
                }
            }*/

            result += ((n - count) % k);

            result += count - l;
            if (result >= MOD) result -= MOD;

            Console.WriteLine(result);

        }

        private static long BinPow(int a, int degr)
        {
            if (degr == 0) return 1;
            if ((degr & 1) == 1) return a * (BinPow(a, degr - 1) % MOD);
            else
            {
                long value = BinPow(a, degr >> 1) % MOD;
                return value * value % MOD;
            }
        }
    }
}


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

namespace Codeforces.R337.C
{
    public static class Solver
    {
        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            WriteAnswer(tw, Parse(tr));
        }

        private static void WriteAnswer(TextWriter tw, int answer)
        {
            tw.WriteLine(answer);
        }

        private static int Parse(TextReader tr)
        {
            var w = tr.ReadLine().Split();
            return Calc(int.Parse(w[0]), int.Parse(w[1]), int.Parse(w[2]));
        }

        public static int Calc(int n, int m, int k)
        {
            var y = n - m;
            var b = y * (k - 1);
            var r = m - b;
            if (r <= 0)
                return m;
            var x = r / k;
            var a = r % k;
            return ((1 << x + 1) - 2) * k + a + b;
        }
    }
}


using System;
using System.Collections.Generic;

namespace Santa_Claus_and_Candies_codeforces753A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int balance = 0;
            List<int> candies = new List<int>();
            int sumOfCandies = 0;
            if (n == 1)
            {
                sumOfCandies = n;
                candies.Add(n);
            }
            else
            {

                for (int i = 1; i < n; i++)
                {
                    sumOfCandies = sumOfCandies + i;
                    if (sumOfCandies > n)
                    {
                        sumOfCandies = sumOfCandies - i;
                        break;
                    }
                    candies.Add(i);
                }
            }

            if (sumOfCandies != n)
            {
                balance = n - sumOfCandies;
                int j = candies.Count - 1;
                candies[j] = candies[j] + balance;
            }
            // printing all the results
            Console.WriteLine(candies.Count);
            foreach (var item in candies)
            {
                Console.Write(item + " ");
            }
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApp
{
    public class Program
    {
        public static void Main()
        {
            int n = Int32.Parse(Console.ReadLine());
            Stack<int> stack = new Stack<int>();
            for (int i = 1; n > 0; i++)
            {
                if (n >= i)
                {
                    n -= i;
                    stack.Push(i);
                }
                else
                {
                    stack.Push(stack.Pop() + n);
                    n = 0;
                }
            }
            Console.WriteLine(stack.Count);
            Console.Write(stack.Pop());
            while (stack.Count > 0)
            {
                Console.Write(" " + stack.Pop());
            }
        }
    }
}


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

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

           int a = Convert.ToInt32(Console.ReadLine());
           List<int> lista = new List<int>();
            lista.Add(1);
           int cont=2;

            if(a==1){
                Console.WriteLine(1);
                Console.WriteLine(1);
            }else if(a==2){
                Console.WriteLine(1);
                Console.WriteLine(2);
            }else{
            while(lista.Sum()!=a){
                if(!lista.Contains(a-lista.Sum())){
                   lista.Add(cont);
                    cont++;
                }else{
                        lista[lista.Count-1]=lista[lista.Count-1]+(a-lista.Sum());
                    }
                }
                 string[]array=new string[lista.Count];
            for(int j=0;j<lista.Count;j++){
                array[j]=lista[j].ToString();
            }
            string result = string.Join(" ", array);
          Console.WriteLine(lista.Count);

            Console.WriteLine(result);
            }

        }
    }
}


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

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for (int i = 0; i < n; i++)
            //{
            //    input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //int n = int.Parse(Console.ReadLine());
            //var arr = new int[n][];//Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for(int i =0; i< n; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //}

            //string s = Console.ReadLine();
            //int n = int.Parse(Console.ReadLine());
            //var arr = new char[n][];//Console.ReadLine().Split().Select(int.Parse).ToArray();

            //for (int i = 0; i < n; i++)
            //{
            //    arr[i] = Console.ReadLine().ToArray();

            //}

            int n = int.Parse(Console.ReadLine());

            var ans = new List<int>();

            if (n > 3)
            {
                while (n>0)
                {
                    if (n == 3)
                    {
                        ans.Add(1);
                        ans.Add(2);
                        break;
                    }
                    else if (n <= 2)
                    {
                        ans.Add(n);
                        break;
                    }
                    else
                    {

                        int a = 0;
                        for (int j = 3; j <n; j++)
                        {
                            bool can = true;
                            for (int i = 2; i <= (int)Math.Sqrt(n); i++)
                            {
                                if (j % i == 0)
                                {
                                    //a = j;
                                    can = false;
                                    break;
                                }
                            }
                            if (can)
                            {
                                //ans.Add(n-j);
                                ans.Add(j);
                                n -= j;
                                break;
                            }
                        }
                    }
                }
            }
            else ans.Add(n);

            ans.Distinct();
            Console.WriteLine(ans.Count());
            Console.WriteLine(string.Join(" ", ans));

            //Console.WriteLine();

            //bool f = true;

            //if (f)
            //{
            //    Console.WriteLine("0000");
            //    f = false;
            //}
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int bull = num[0];
            //int cow = num[1];
            //var memo = new bool[4,4];
            //int count = 0;
            //var list = new List<int>();
            //bool first = false;
            //if (bull  != 4)
            //{

            //    var ans = new char[4];

            //    if(count<9 && cow>0 && list.Count()<4)
            //    {
            //        for(int i=0; i< cow; i++)
            //        {
            //            list.Add(count);
            //        }
            //        ans[0] = (char)(count+'0'+1);
            //        ans[1] = (char)(count+'0' + 1);
            //        ans[2] = (char)(count+'0' + 1);
            //        ans[3] = (char)(count+'0' + 1);
            //        first = true;
            //    }
            //    else
            //    {
            //        if(first)
            //        {
            //            ans[0] = (char)(list[0]+'0');
            //            ans[1] = (char)(list[1]+'0');
            //            ans[2] = (char)(list[2]+'0');
            //            ans[3] = (char)(list[3]+'0');

            //            count = 0;
            //            first = false;
            //        }
            //        else
            //        {
            //            char tmp = ans[0];
            //            char tmp2 = ans[1];
            //            char tmp3 = ans[2];
            //            if(count%2==0)
            //            {
            //                ans[0] = ans[2];
            //                ans[2] = tmp;
            //                ans[1] = ans[3];
            //                ans[3] = tmp2;
            //            }
            //            else
            //            {
            //                ans[0] = ans[1];
            //                ans[1] = tmp;
            //                ans[2] = ans[3];
            //                ans[3] = tmp3;
            //            }

            //        }

            //    }

            //    count++;
            //    Console.WriteLine(new string(ans));
            //}
            //else Console.WriteLine();

        }

    }

    class Segment
    {
        public Tuple<long, int>[] arr;
        int n;

        public Segment(int n)
        {
            this.n = n * 2;
            //arr = Enumerable.Range(0, n*2).ToArray();
            arr = new Tuple<long, int>[this.n];
            for (int i = 0; i < this.n; i++)
            {
                arr[i] = Tuple.Create((long)0, 0);
            }

        }

        public void update(int i, long x, int ind)
        {
            i = (n / 2) + i - 1;
            arr[i] = Tuple.Create(x, ind);
            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Max(arr[i*2+1], arr[i*2+2]);
                if (arr[i * 2 + 1].Item1 > arr[i * 2 + 2].Item1)
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 1].Item1, arr[i * 2 + 1].Item2);
                }
                else
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 2].Item1, arr[i * 2 + 2].Item2);
                }

            }

        }

        //call : query(a,b, 0, 0, n)
        public long query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return int.MaxValue;
            if (a <= l && r <= b) return arr[k].Item1;
            else
            {
                long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return Math.Max(vl, vr);
            }
        }

    }

    class UnionFind
    {
        public int[] path;

        public UnionFind(int n)
        {
            path = new int[n];

            for (int i = 0; i < n; i++)
            {
                path[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }

        public bool find(int p, int q)
        {
            return root(p) == root(q);
        }

        public void unite(int p, int q)
        {
            int i = root(p);
            int j = root(q);
            path[i] = j;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

class Test
{

    static long MOD = 1000000007;
    static long[] fact = new long[500001];
    static long[] factInv = new long[500001];
    static List<int> anss = new List<int>();
    // Driver code
    public static void Main()
    {

        //int t = int.Parse(Console.ReadLine());
        //while (t > 0)
        {
            //  t--;
            var input1 = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray();
            var n = input1[0];
            // var k = input1[1];
            // var arr = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray();
            int i = 1;
            List<int> lst = new List<int>();
            var ans = 0;
            for (; i <= n; i++)
            {
                ans = (i * (i + 1)) / 2;
                lst.Add(ans);
                if (ans > n)
                {
                    break;
                }
            }

            Console.WriteLine(i - 1);
            var left = ans - n;
            int j = 0;
            for (; j < left; j++)
            {
                Console.Write(lst[j] + 1 + " ");
            }
            for (; j < lst.Count-1; j++)
            {
                Console.Write(lst[j] + " ");
            }

        }

    }

    public static long FastPower(long a, long b)
    {
        if (b == 0)
            return 1;

        var val = FastPower(a, b / 2);

        if (b % 2 == 0)
            return val * val % MOD;
        else
            return val * val % MOD * a % MOD;
    }

    public static void Fact()
    {
        fact[0] = 1;
        factInv[0] = FastPower(fact[0], MOD - 2);

        for (int i = 1; i <= 500000; i++)
        {
            fact[i] = i * fact[i - 1] % MOD;
            factInv[i] = FastPower(fact[i], MOD - 2);
        }

    }

    public static long NCR(long n, long r)
    {
        return fact[n] * factInv[r] % MOD * factInv[n - r] % MOD;
    }
}


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

namespace _753A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n <= 2)
            {
                Console.WriteLine("1");
                Console.WriteLine(n);
                //Console.ReadLine();
                return;
            }

            int maxK = 0, maxAF = 0, maxAL = 0, maxStep = 0;
            for (int aF = 1; aF < n; aF++)
            {
                for (int aL = 1; aL < n; aL++)
                {
                    double k = (2D * n) / ((double)aF + aL);
                    if (Math.Floor(k) == k && k > maxK)
                    {
                        int step = (aL - aF) / ((int)k - 1);
                        if (step > 0)
                        {
                            maxK = (int)k;
                            maxAF = aF;
                            maxAL = aL;
                            maxStep = step;
                        }
                    }
                }
            }

            int[] answer = new int[maxK];
            answer[0] = maxAF;
            answer[maxK - 1] = maxAL;
            for (int i = 1; i < maxK - 1; i++)
            {
                answer[i] = maxAF + i * maxStep;
            }

            Console.WriteLine(maxK);
            Console.WriteLine(string.Join(" ", answer));
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

class Test
{

    static long MOD = 1000000007;
    static long[] fact = new long[500001];
    static long[] factInv = new long[500001];
    static List<int> anss = new List<int>();
    // Driver code
    public static void Main()
    {

        //int t = int.Parse(Console.ReadLine());
        //while (t > 0)
        {
            //  t--;
            var input1 = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray();
            var n = input1[0];
            // var k = input1[1];
            // var arr = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray();
            int i = 1;
            List<int> lst = new List<int>();
            var ans = 0;
            for (; i <= n; i++)
            {
                ans = ans + i;
                lst.Add(i);
                if (ans > n)
                {
                    break;
                }
            }

            Console.WriteLine(i - 1);
            var left = n-(ans  - i);
            int j = 0;
            for (; j < left; j++)
            {
                Console.Write(lst[j] + 1 + " ");
            }
            for (; j < lst.Count - 1; j++)
            {
                Console.Write(lst[j] + " ");
            }

        }

    }

    public static long FastPower(long a, long b)
    {
        if (b == 0)
            return 1;

        var val = FastPower(a, b / 2);

        if (b % 2 == 0)
            return val * val % MOD;
        else
            return val * val % MOD * a % MOD;
    }

    public static void Fact()
    {
        fact[0] = 1;
        factInv[0] = FastPower(fact[0], MOD - 2);

        for (int i = 1; i <= 500000; i++)
        {
            fact[i] = i * fact[i - 1] % MOD;
            factInv[i] = FastPower(fact[i], MOD - 2);
        }

    }

    public static long NCR(long n, long r)
    {
        return fact[n] * factInv[r] % MOD * factInv[n - r] % MOD;
    }
}


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

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

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

        object Solve()
        {
            var m = ReadLong();
            var d = ReadLong();
            if (m == 2)
                return d == 1 ? 4 : 5;

            var ms = new long[] { 1, 3, 5, 7, 8, 10, 12 };
            if (ms.Contains(m))
                return d == 6 || d == 7 ? 6 : 5;
            return d == 7 ? 6 : 5;

        }
        //object Solve()
        //{
        //    checked
        //    {
        //        var n = ReadLong();
        //        var s = Read().Select(x => long.Parse(x.ToString())).ToArray();
        //        var dp = new Tuple<int, long>[60];
        //        dp[0] = Tuple.Create(0, s[0]);
        //        for (int i = 1; i < s.Length; i++)
        //        {
        //            if (s[i] == 1 && s[i - 1] < 6)
        //            {
        //                var r = i == 1 ? -1 : dp[i - 2].Item1;
        //                var prevRes = i == 1 ? 0 : dp[i - 2].Item2;
        //                dp[i] = Tuple.Create(r + 1, FastPow(16, r + 1) * (10 + s[i - 1]) + prevRes);
        //            }
        //            else
        //            {
        //                var r = dp[i - 1].Item1;
        //                var prevRes = dp[i - 1].Item2;
        //                dp[i] = Tuple.Create(r + 1, FastPow(16, r + 1) * s[i] + prevRes);
        //            }
        //        }
        //        return dp[s.Length - 1].Item2;
        //    }
        //}
        //Tuple<int, long> Check(long bas, int[] s, int i)
        //{
        //    var strB = bas.ToString().Select(x => int.Parse(x.ToString())).ToArray();
        //    if (i < strB.Length - 1)
        //        return Tuple.Create(-1, 0L);
        //    for (int j = 0; j < strB.Length; j++)
        //    {
        //        if (strB[j] < s[i - j])
        //        {
        //            for (int i = 0; i < strB.Le; i++)
        //            {

        //            }

        //                }
        //    }
        //}

        long FastPow(long b, long pow)
        {
            if (pow == 0)
                return 1;
            if (pow == 1)
                return b;
            if (pow % 2 == 0)
                return FastPow(b * b, pow / 2);
            return b * FastPow(b, pow - 1);
        }

        bool IsPrime(int n)
        {
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                    return false;
            }
            return true;
        }
    }

    class DSU
    {
        private int[] arr;
        private Random r = new Random();
        public DSU(int n)
        {
            arr = new int[n];
            for (int i = 0; i < n; i++)
            {
                arr[i] = i;
            }
        }

        public int Find(int x)
        {
            if (arr[arr[x]] == arr[x])
                return arr[x];
            var y = Find(arr[x]);
            arr[x] = y;
            return y;
        }

        public void Union(int x, int y)
        {
            var p1 = Find(x);
            var p2 = Find(y);
            if (p1 == p2)
                return;
            if (r.NextDouble() < 0.5)
                arr[p1] = p2;
            else
                arr[p2] = p1;
        }

        public int[][] Enumerate()
        {
            return arr.Select((x, i) => new { g = Find(x), i }).GroupBy(x => x.g, (k, e) => e.Select(y => y.i).ToArray()).ToArray();
        }
    }

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

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

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

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

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

        private bool GetProd()
        {

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

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

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

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

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


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

class cf001
{
    static void Main()
    {
        string input = Console.ReadLine();
        int month = int.Parse(input.Split()[0]);
        int weekday = int.Parse(input.Split()[1]);
        int result;
        List<int> months = new List<int>() { 1, 3, 5, 7, 8, 10, 12 };

        if (month == 2 && weekday == 1)
        {
            result = 4;
        }
        else if (month == 2)
        {
            result = 5;
        }
        else if ((months.Contains(month)&& weekday > 5) ||(weekday>6))
        {
            result = 6;
        }else
        {
            result = 5;
        }

        Console.WriteLine(result);
    }
}


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

namespace ConsoleApplication2
{
    class Program
    {
        static int Number(int dataWeek, int dataMonth)
        {
            int res = 0;
            if ((dataMonth % 2 != 0 && dataMonth <= 7) || (dataMonth % 2 == 0 && dataMonth >= 8))
            {
                if(dataWeek <= 5)
                {
                    res = 5;
                }
                else
                {
                    res = 6;
                }
            }
            else if(dataMonth == 2)
            {
                if(dataWeek == 1)
                {
                    res = 4;
                }
                else
                {
                    res = 5;
                }
            }
            else
            {
                if(dataWeek <= 6)
                {
                    res = 5;
                }
                else
                {
                    res = 6;
                }
            }
            return res;
        }
        private static void Main(string[] args)
        {
            int[] data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int dataMonth = data[0];
            int dataWeek = data[1];

            int result = Number(dataWeek, dataMonth);
            Console.WriteLine(result);
        }
    }
}


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

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

            string[] x = Console.ReadLine().Split(' ');

            int[] s = new int[2];

            for (int i = 0; i < 2; i++)
            {
                s[i] = int.Parse(x[i]);
            }

            if (s[0] == 1 || s[0] == 3 || s[0] == 5 || s[0] == 7 || s[0] == 8 || s[0] == 10 || s[0] == 12)
            {
                if (s[1] == 6 || s[1] == 7)
                {
                    Console.WriteLine(6);
                }
                else if (s[1] == 1 || s[1] == 2 || s[1] == 3 || s[1] == 4 ||s[1]==5)
                {
                    Console.WriteLine(5);

                }
            }
            else if (s[0] == 2 && s[1] == 1)
            {
                Console.WriteLine(4);
            }
            else if (s[0] == 2 && s[1] != 1)
            {
                Console.WriteLine(5);
            }

            else if(s[0] == 4 || s[0] == 6 || s[0] == 9|| s[0] == 11 )
            {
                if ( s[1] == 7)
                {
                    Console.WriteLine(6);

                }
                else
                {
                    Console.WriteLine(5);
                }

            }
            Console.ReadLine();

        }
    }
}


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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] menesiuIlgumai = new int[13] {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            string[] duomenys = Console.ReadLine().Split(' ');
            int m = int.Parse(duomenys[0]);
            int d = int.Parse(duomenys[1]);
            int columns = 1;
            int menesioIlgumas = menesiuIlgumai[m];
            menesioIlgumas -= (8 - d);
            columns += menesioIlgumas % 7 == 0 ? menesioIlgumas / 7 : (menesioIlgumas / 7) + 1;
            Console.WriteLine(columns);
        }
    }
}


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

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

        private static void Main(string[] args)
        {
            int m = Next();
            int d = Next();

            int days = DateTime.DaysInMonth(2017, m);
            days -= 8 - d;
            int count = 1 + (days+6)/7;

            writer.WriteLine(count);
            writer.Flush();
        }

        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 static System.Console;
class Solution
{
    static void Main(string[] args)
    {
        int[] a = Array.ConvertAll(ReadLine().Split(), int.Parse);
        int days = DateTime.DaysInMonth(2021, a[0]);
        int weeks = days > 28 ? 5 : 4;
        weeks += 8-a[1] >= days - 28  ? 0 : 1;
        WriteLine(weeks);
    }

}


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

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

            string[] x = Console.ReadLine().Split(' ');

            int[] s = new int[2];

            for (int i = 0; i < 2; i++)
            {
                s[i] = int.Parse(x[i]);
            }
            //31---->1,3,5,7,8,10,12
            if (s[0] == 1||s[0]==3||s[0]==5||s[0]==7||s[0]==8||s[0]==10||s[0]==12 )
            {
                if (s[1] == 6 || s[1] == 7)
                {
                    Console.WriteLine(6);
                }
                else
                {
                    Console.WriteLine(5);
                }

            }
         //29--->2
            else if  (s[0] == 2 && s[1] == 1)
            {
                Console.WriteLine(4);
            }
            else if (s[0] >= 1 && s[1] == 6 || s[1] == 7)
            {
                Console.WriteLine(6);

            }
            //30
            else
            {
                Console.WriteLine(5);

            }
            Console.ReadLine();

        }
    }
}


using System;

class A
{
  public static void Main()
  {
    int[] mouth = new int[]{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    int total = 0;

    string line = Console.ReadLine();

    int m = int.Parse(line.Split(' ')[0]),
        d = int.Parse(line.Split(' ')[1]);

    d =  mouth[d] - (7-d);
    total = Math.Abs(d / 7) + 1;

    Console.WriteLine(total);
  }
}


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

namespace CF
{
    class B104
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            string sa = s[0];
            string sb = s[1];
            int la = sa.Length;
            int lb = sb.Length;
            string bi = "";
            for (int ii = 0; ii < lb; ii++)
                bi += sb[lb-1-ii];
            b = int.Parse(bi);

            int i;

            for (i = a + 1; i < 101010; i++ )
            {
                int d = i;
                int m = 0;
                int c = 0;
                while (d > 0)
                {
                    c = d % 10;
                    if (c==4 || c==7)
                        m = m*10+c;
                    d /= 10;
                }
                if (m == b)
                    break;
            }

            Console.WriteLine(i);

   //         Console.ReadKey();
        }
    }
}


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

namespace task146_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            Int32 a = Int32.Parse(input[0]);
            Int32 b = Int32.Parse(input[1]);
            while (Regex.Replace(a.ToString(), "[^47]", "") != input[1])
            {
                a++;
            }
            Console.WriteLine(a);
            //Console.ReadLine();
        }
    }
}


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 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 void Main()
        {
            var input = ReadArray();
            var a = ReadNextInt(input, 0);
            var b = ReadNextInt(input, 1);
            if (b > a)
            {
                Console.WriteLine(b);
                return;
            }
            var bStr = input[1];
            while (true)
            {
                var aStr = a.ToString();
                var cur = 0;
                for (int i = 0; i < aStr.Length; i++)
                {
                    if (aStr[i] == '4' || aStr[i] == '7')
                    {
                        if (bStr[cur] == aStr[i])
                            cur++;
                        else
                        {
                            break;
                        }
                    }
                }
                if (cur == bStr.Length)
                {
                    Console.WriteLine(a);
                    return;
                }
                a++;
            }
        }
    }
}


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 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 void Main()
        {
            var input = ReadArray();
            var a = ReadNextInt(input, 0);
            var b = ReadNextInt(input, 1);
            if (b > a)
            {
                Console.WriteLine(b);
                return;
            }
            if(b == a)
            {
                Console.WriteLine("1" + b);
                return;
            }
            var bStr = input[1];
            while (true)
            {
                var aStr = a.ToString();
                var cur = 0;
                var valid = true;
                foreach (char t in aStr)
                {
                    if (t == '4' || t == '7')
                    {
                        if (cur == bStr.Length || bStr[cur] != t)
                        {
                            valid = false;
                            break;
                        }

                        cur++;
                    }
                }
                if (valid)
                {
                    Console.WriteLine(a);
                    return;
                }
                a++;
            }
        }
    }
}


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

namespace CodeForceContest
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ').Select(ss => int.Parse(ss)).ToArray();
            //var s = "17 7".Split(' ').Select(ss => int.Parse(ss)).ToArray();
            var a = s[0];
            var b = s[1];
            var aa = String.Join("",a.ToString().Take(a.ToString().Length - b.ToString().Length).Select(sss=>sss.ToString()).ToArray());
            aa += b.ToString();
            if(a<int.Parse(aa))Console.WriteLine(aa);
            else
            {
                var c = String.Join("", a.ToString().Take(a.ToString().Length - b.ToString().Length).Select(sss => sss.ToString()).ToArray());
                var t = (c == String.Empty ? 0 : int.Parse(c)) + 1;
                c = t.ToString()+b.ToString();
                Console.WriteLine(c);
            }
        }

    }
}


using System;

class Program{
	static void Main(){
		string[] input = Console.ReadLine().Split();
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);

		if(b > a){
			Console.WriteLine(b);
		}else{
			int i = 4;
			while(true){
				int t = 0;
				string tmp = i.ToString().Replace("0", "").Replace("1", "").Replace("2", "").Replace("3", "").Replace("5", "").Replace("6", "").Replace("8", "").Replace("9", "");
				if(tmp.Length > 0)
					t = int.Parse(tmp);
				if(t == b && i > a){
					Console.WriteLine(i);
					break;
				}
				i++;
			}
		}
	}
}


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

namespace CodeForces
{
    class R175_Div2_D
    {
        static void Main(string[] args)
        {
            long mod = 1000000007;
            int n = int.Parse(Console.ReadLine());

            long f = 1;
            for (int i = 1; i <= n; i++)
                f *= i;

            f *= f;

            for (int i = 1; i <= n-2; i++)
                f /= 2;

            f = f % mod;

            if (n == 2)
                Console.WriteLine(0);
            else
                Console.WriteLine(f);
        }
    }
}


using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using EducationalCodeforcesRound86.Questions;
using ModInt = EducationalCodeforcesRound86.Questions.StaticModInt<EducationalCodeforcesRound86.Questions.Mod998244353>;

namespace EducationalCodeforcesRound86.Questions
{
    public class QuestionE : AtCoderQuestionBase
    {
        [MethodImpl(MethodImplOptions.AggressiveOptimization)]
        public override void Solve(IOManager io)
        {
            var n = io.ReadInt();
            var pairs = io.ReadInt();

            if (pairs >= n)
            {
                io.WriteLine(0);
                return;
            }

            var combination = new ModCombination<Mod998244353>();
            var available = n - pairs;

            var result = ModInt.Zero;

            for (int sub = 0; sub < available; sub++)
            {
                var sign = sub % 2 == 0 ? ModInt.One : -ModInt.One;
                result += sign * combination.Combination(available, available - sub) * ModInt.Raw(available - sub).Pow(n);
            }

            result *= combination.Combination(n, available);

            if (pairs != 0)
            {
                result *= ModInt.Raw(2);
            }

            io.WriteLine(result);
        }
    }

    ///
    /// コンパイル時に決定する mod を表します。
    ///
    /// <example>
    ///
    /// public readonly struct Mod1000000009 : IStaticMod
    /// {
    ///     public uint Mod => 1000000009;
    ///     public bool IsPrime => true;
    /// }
    ///
    /// </example>
    public interface IStaticMod
    {
        ///
        /// mod を取得します。
        ///
        uint Mod { get; }

        ///
        /// mod が素数であるか識別します。
        ///
        bool IsPrime { get; }
    }

    public readonly struct Mod1000000007 : IStaticMod
    {
        public uint Mod => 1000000007;
        public bool IsPrime => true;
    }

    public readonly struct Mod998244353 : IStaticMod
    {
        public uint Mod => 998244353;
        public bool IsPrime => true;
    }

    ///
    /// 実行時に決定する mod の ID を表します。
    ///
    /// <example>
    ///
    /// public readonly struct ModID123 : IDynamicModID { }
    ///
    /// </example>
    public interface IDynamicModID { }

    public readonly struct ModID0 : IDynamicModID { }
    public readonly struct ModID1 : IDynamicModID { }
    public readonly struct ModID2 : IDynamicModID { }

    ///
    /// 四則演算時に自動で mod を取る整数型。mod の値はコンパイル時に決定している必要があります。
    ///
    /// <typeparam name="T">定数 mod を表す構造体</typeparam>
    /// <example>
    ///
    /// using ModInt = AtCoder.StaticModInt<AtCoder.Mod1000000007>;
    ///
    /// void SomeMethod()
    /// {
    ///     var m = new ModInt(1);
    ///     m -= 2;
    ///     Console.WriteLine(m);   // 1000000006
    /// }
    ///
    /// </example>
    public readonly struct StaticModInt<T> : IEquatable<StaticModInt<T>> where T : struct, IStaticMod
    {
        private readonly uint _v;

        ///
        /// 格納されている値を返します。
        ///
        public int Value => (int)_v;

        ///
        /// mod を返します。
        ///
        public static int Mod => (int)default(T).Mod;

        public static StaticModInt<T> Zero => new StaticModInt<T>();
        public static StaticModInt<T> One => new StaticModInt<T>(1u);

        ///
        /// <paramref name="v"/> に対して mod を取らずに StaticModInt<<typeparamref name="T"/>> 型のインスタンスを生成します。
        ///
        /// <remarks>
        /// <para>定数倍高速化のための関数です。 <paramref name="v"/> に 0 未満または mod 以上の値を入れた場合の挙動は未定義です。</para>
        /// <para>制約: 0≤|<paramref name="v"/>|<mod</para>
        /// </remarks>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static StaticModInt<T> Raw(int v)
        {
            var u = unchecked((uint)v);
            Debug.Assert(u < Mod);
            return new StaticModInt<T>(u);
        }

        ///
        /// StaticModInt<<typeparamref name="T"/>> 型のインスタンスを生成します。
        ///
        /// <remarks>
        /// <paramref name="v"/>が 0 未満、もしくは mod 以上の場合、自動で mod を取ります。
        /// </remarks>
        public StaticModInt(long v) : this(Round(v)) { }

        private StaticModInt(uint v) => _v = v;

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static uint Round(long v)
        {
            var x = v % default(T).Mod;
            if (x < 0)
            {
                x += default(T).Mod;
            }
            return (uint)x;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static StaticModInt<T> operator ++(StaticModInt<T> value)
        {
            var v = value._v + 1;
            if (v == default(T).Mod)
            {
                v = 0;
            }
            return new StaticModInt<T>(v);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static StaticModInt<T> operator --(StaticModInt<T> value)
        {
            var v = value._v;
            if (v == 0)
            {
                v = default(T).Mod;
            }
            return new StaticModInt<T>(v - 1);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static StaticModInt<T> operator +(StaticModInt<T> lhs, StaticModInt<T> rhs)
        {
            var v = lhs._v + rhs._v;
            if (v >= default(T).Mod)
            {
                v -= default(T).Mod;
            }
            return new StaticModInt<T>(v);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static StaticModInt<T> operator -(StaticModInt<T> lhs, StaticModInt<T> rhs)
        {
            unchecked
            {
                var v = lhs._v - rhs._v;
                if (v >= default(T).Mod)
                {
                    v += default(T).Mod;
                }
                return new StaticModInt<T>(v);
            }
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static StaticModInt<T> operator *(StaticModInt<T> lhs, StaticModInt<T> rhs)
        {
            return new StaticModInt<T>((uint)((ulong)lhs._v * rhs._v % default(T).Mod));
        }

        ///
        /// 除算を行います。
        ///
        /// <remarks>
        /// <para>- 制約: <paramref name="rhs"/> に乗法の逆元が存在する。（gcd(<paramref name="rhs"/>, mod) = 1）</para>
        /// <para>- 計算量: O(log(mod))</para>
        /// </remarks>
        public static StaticModInt<T> operator /(StaticModInt<T> lhs, StaticModInt<T> rhs) => lhs * rhs.Inverse();

        public static StaticModInt<T> operator +(StaticModInt<T> value) => value;
        public static StaticModInt<T> operator -(StaticModInt<T> value) => new StaticModInt<T>() - value;
        public static bool operator ==(StaticModInt<T> lhs, StaticModInt<T> rhs) => lhs._v == rhs._v;
        public static bool operator !=(StaticModInt<T> lhs, StaticModInt<T> rhs) => lhs._v != rhs._v;
        public static implicit operator StaticModInt<T>(int value) => new StaticModInt<T>(value);
        public static implicit operator StaticModInt<T>(long value) => new StaticModInt<T>(value);

        ///
        /// 自身を x として、x^<paramref name="n"/> を返します。
        ///
        /// <remarks>
        /// <para>制約: 0≤|<paramref name="n"/>|</para>
        /// <para>計算量: O(log(<paramref name="n"/>))</para>
        /// </remarks>
        public StaticModInt<T> Pow(long n)
        {
            Debug.Assert(0 <= n);
            var x = this;
            var r = Raw(1);

            while (n > 0)
            {
                if ((n & 1) > 0)
                {
                    r *= x;
                }
                x *= x;
                n >>= 1;
            }

            return r;
        }

        ///
        /// 自身を x として、 xy≡1 なる y を返します。
        ///
        /// <remarks>
        /// <para>制約: gcd(x, mod) = 1</para>
        /// </remarks>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public StaticModInt<T> Inverse()
        {
            if (default(T).IsPrime)
            {
                Debug.Assert(_v > 0);
                return Pow(default(T).Mod - 2);
            }
            else
            {
                var (g, x) = InternalMath.InvGCD(_v, default(T).Mod);
                Debug.Assert(g == 1);
                return new StaticModInt<T>(x);
            }
        }

        public override string ToString() => _v.ToString();
        public override bool Equals(object obj) => obj is StaticModInt<T> && Equals((StaticModInt<T>)obj);
        public bool Equals(StaticModInt<T> other) => Value == other.Value;
        public override int GetHashCode() => _v.GetHashCode();
    }

    ///
    /// 四則演算時に自動で mod を取る整数型。実行時に mod が決まる場合でも使用可能です。
    ///
    /// <remarks>
    /// 使用前に DynamicModInt<<typeparamref name="T"/>>.Mod に mod の値を設定する必要があります。
    /// </remarks>
    /// <typeparam name="T">mod の ID を表す構造体</typeparam>
    /// <example>
    ///
    /// using AtCoder.ModInt = AtCoder.DynamicModInt<AtCoder.ModID0>;
    ///
    /// void SomeMethod()
    /// {
    ///     ModInt.Mod = 1000000009;
    ///     var m = new ModInt(1);
    ///     m -= 2;
    ///     Console.WriteLine(m);   // 1000000008
    /// }
    ///
    /// </example>
    public readonly struct DynamicModInt<T> : IEquatable<DynamicModInt<T>> where T : struct, IDynamicModID
    {
        private readonly uint _v;
        private static Barrett bt;

        ///
        /// 格納されている値を返します。
        ///
        public int Value => (int)_v;

        ///
        /// mod を返します。
        ///
        public static int Mod
        {
            get => (int)bt.Mod;
            set
            {
                Debug.Assert(1 <= value);
                bt = new Barrett((uint)value);
            }
        }

        ///
        /// <paramref name="v"/> に対して mod を取らずに DynamicModInt<<typeparamref name="T"/>> 型のインスタンスを生成します。
        ///
        /// <remarks>
        /// <para>定数倍高速化のための関数です。 <paramref name="v"/> に 0 未満または mod 以上の値を入れた場合の挙動は未定義です。</para>
        /// <para>制約: 0≤|<paramref name="v"/>|<mod</para>
        /// </remarks>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static DynamicModInt<T> Raw(int v)
        {
            var u = unchecked((uint)v);
            Debug.Assert(bt != null, $"使用前に {nameof(DynamicModInt<T>)}<{nameof(T)}>.{nameof(Mod)} プロパティに mod の値を設定してください。");
            Debug.Assert(u < Mod);
            return new DynamicModInt<T>(u);
        }

        ///
        /// DynamicModInt<<typeparamref name="T"/>> 型のインスタンスを生成します。
        ///
        /// <remarks>
        /// <para>- 使用前に DynamicModInt<<typeparamref name="T"/>>.Mod に mod の値を設定する必要があります。</para>
        /// <para>- <paramref name="v"/> が 0 未満、もしくは mod 以上の場合、自動で mod を取ります。</para>
        /// </remarks>
        public DynamicModInt(long v) : this(Round(v)) { }

        private DynamicModInt(uint v) => _v = v;

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static uint Round(long v)
        {
            Debug.Assert(bt != null, $"使用前に {nameof(DynamicModInt<T>)}<{nameof(T)}>.{nameof(Mod)} プロパティに mod の値を設定してください。");
            var x = v % bt.Mod;
            if (x < 0)
            {
                x += bt.Mod;
            }
            return (uint)x;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static DynamicModInt<T> operator ++(DynamicModInt<T> value)
        {
            var v = value._v + 1;
            if (v == bt.Mod)
            {
                v = 0;
            }
            return new DynamicModInt<T>(v);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static DynamicModInt<T> operator --(DynamicModInt<T> value)
        {
            var v = value._v;
            if (v == 0)
            {
                v = bt.Mod;
            }
            return new DynamicModInt<T>(v - 1);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static DynamicModInt<T> operator +(DynamicModInt<T> lhs, DynamicModInt<T> rhs)
        {
            var v = lhs._v + rhs._v;
            if (v >= bt.Mod)
            {
                v -= bt.Mod;
            }
            return new DynamicModInt<T>(v);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static DynamicModInt<T> operator -(DynamicModInt<T> lhs, DynamicModInt<T> rhs)
        {
            unchecked
            {
                var v = lhs._v - rhs._v;
                if (v >= bt.Mod)
                {
                    v += bt.Mod;
                }
                return new DynamicModInt<T>(v);
            }
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static DynamicModInt<T> operator *(DynamicModInt<T> lhs, DynamicModInt<T> rhs)
        {
            uint z = bt.Mul(lhs._v, rhs._v);
            return new DynamicModInt<T>(z);
        }

        ///
        /// 除算を行います。
        ///
        /// <remarks>
        /// <para>- 制約: <paramref name="rhs"/> に乗法の逆元が存在する。（gcd(<paramref name="rhs"/>, mod) = 1）</para>
        /// <para>- 計算量: O(log(mod))</para>
        /// </remarks>
        public static DynamicModInt<T> operator /(DynamicModInt<T> lhs, DynamicModInt<T> rhs) => lhs * rhs.Inverse();

        public static DynamicModInt<T> operator +(DynamicModInt<T> value) => value;
        public static DynamicModInt<T> operator -(DynamicModInt<T> value) => new DynamicModInt<T>() - value;
        public static bool operator ==(DynamicModInt<T> lhs, DynamicModInt<T> rhs) => lhs._v == rhs._v;
        public static bool operator !=(DynamicModInt<T> lhs, DynamicModInt<T> rhs) => lhs._v != rhs._v;
        public static implicit operator DynamicModInt<T>(int value) => new DynamicModInt<T>(value);
        public static implicit operator DynamicModInt<T>(long value) => new DynamicModInt<T>(value);

        ///
        /// 自身を x として、x^<paramref name="n"/> を返します。
        ///
        /// <remarks>
        /// <para>制約: 0≤|<paramref name="n"/>|</para>
        /// <para>計算量: O(log(<paramref name="n"/>))</para>
        /// </remarks>
        public DynamicModInt<T> Pow(long n)
        {
            Debug.Assert(0 <= n);
            var x = this;
            var r = Raw(1);

            while (n > 0)
            {
                if ((n & 1) > 0)
                {
                    r *= x;
                }
                x *= x;
                n >>= 1;
            }

            return r;
        }

        ///
        /// 自身を x として、 xy≡1 なる y を返します。
        ///
        /// <remarks>
        /// <para>制約: gcd(x, mod) = 1</para>
        /// </remarks>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public DynamicModInt<T> Inverse()
        {
            var (g, x) = InternalMath.InvGCD(_v, bt.Mod);
            Debug.Assert(g == 1);
            return new DynamicModInt<T>(x);
        }

        public override string ToString() => _v.ToString();
        public override bool Equals(object obj) => obj is DynamicModInt<T> && Equals((DynamicModInt<T>)obj);
        public bool Equals(DynamicModInt<T> other) => Value == other.Value;
        public override int GetHashCode() => _v.GetHashCode();
    }

    ///
    /// Fast moduler by barrett reduction
    /// <seealso href="https://en.wikipedia.org/wiki/Barrett_reduction"/>
    ///
    public class Barrett
    {
        public uint Mod { get; private set; }
        private ulong IM;
        public Barrett(uint m)
        {
            Mod = m;
            IM = unchecked((ulong)-1) / m + 1;
        }

        ///
        /// <paramref name="a"/> * <paramref name="b"/> mod m
        ///
        public uint Mul(uint a, uint b)
        {
            ulong z = a;
            z *= b;
            if (!Bmi2.X64.IsSupported) return (uint)(z % Mod);
            var x = Bmi2.X64.MultiplyNoFlags(z, IM);
            var v = unchecked((uint)(z - x * Mod));
            if (Mod <= v) v += Mod;
            return v;
        }
    }

    public static class InternalMath
    {
        ///
        /// g=gcd(a,b),xa=g(mod b) となるような 0≤x<b/g の(g, x)
        ///
        /// <remarks>
        /// <para>制約: 1≤<paramref name="b"/></para>
        /// </remarks>
        public static (long, long) InvGCD(long a, long b)
        {
            a = SafeMod(a, b);
            if (a == 0) return (b, 0);

            long s = b, t = a;
            long m0 = 0, m1 = 1;

            long u;
            while (true)
            {
                if (t == 0)
                {
                    if (m0 < 0) m0 += b / s;
                    return (s, m0);
                }
                u = s / t;
                s -= t * u;
                m0 -= m1 * u;

                if (s == 0)
                {
                    if (m1 < 0) m1 += b / t;
                    return (t, m1);
                }
                u = t / s;
                t -= s * u;
                m1 -= m0 * u;
            }
        }

        public static long SafeMod(long x, long m)
        {
            x %= m;
            if (x < 0) x += m;
            return x;
        }
    }

    public class ModCombination<T> where T : struct, IStaticMod
    {
        readonly StaticModInt<T>[] _factorials;
        readonly StaticModInt<T>[] _invFactorials;

        public ModCombination(int max = 1000000)
        {
            if (max >= default(T).Mod)
            {
                ThrowArgumentOutOfRangeException();
            }

            _factorials = new StaticModInt<T>[max + 1];
            _invFactorials = new StaticModInt<T>[max + 1];

            _factorials[0] = _factorials[1] = StaticModInt<T>.Raw(1);
            _invFactorials[0] = _invFactorials[1] = StaticModInt<T>.Raw(1);

            for (int i = 2; i < _factorials.Length; i++)
            {
                _factorials[i] = _factorials[i - 1] * StaticModInt<T>.Raw(i);
            }

            _invFactorials[^1] = _factorials[^1].Inverse();

            for (int i = _invFactorials.Length - 2; i >= 0; i--)
            {
                _invFactorials[i] = _invFactorials[i + 1] * StaticModInt<T>.Raw(i + 1);
            }
        }

        public StaticModInt<T> Factorial(int n) => _factorials[n];

        public StaticModInt<T> Permutation(int n, int k) => _factorials[n] * _invFactorials[n - k];

        public StaticModInt<T> Combination(int n, int k) => _factorials[n] * _invFactorials[k] * _invFactorials[n - k];

        public StaticModInt<T> CombinationWithRepetition(int n, int k) => Combination(n + k - 1, k);

        public void ThrowArgumentOutOfRangeException() => throw new ArgumentOutOfRangeException();
    }
}

namespace EducationalCodeforcesRound86
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionE();
            using var io = new IOManager(Console.OpenStandardInput(), Console.OpenStandardOutput());
            question.Solve(io);
        }
    }
}

#region Base Class

namespace EducationalCodeforcesRound86.Questions
{
    public interface IAtCoderQuestion
    {
        string Solve(string input);
        void Solve(IOManager io);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public string Solve(string input)
        {
            var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(input));
            var outputStream = new MemoryStream();
            using var manager = new IOManager(inputStream, outputStream);

            Solve(manager);
            manager.Flush();

            outputStream.Seek(0, SeekOrigin.Begin);
            var reader = new StreamReader(outputStream);
            return reader.ReadToEnd();
        }

        public abstract void Solve(IOManager io);
    }
}

#endregion

#region Utils

namespace EducationalCodeforcesRound86
{
    public class IOManager : IDisposable
    {
        private readonly BinaryReader _reader;
        private readonly StreamWriter _writer;
        private bool _disposedValue;
        private byte[] _buffer = new byte[1024];
        private int _length;
        private int _cursor;
        private bool _eof;

        const char ValidFirstChar = '!';
        const char ValidLastChar = '~';

        public IOManager(Stream input, Stream output)
        {
            _reader = new BinaryReader(input);
            _writer = new StreamWriter(output) { AutoFlush = false };
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private char ReadAscii()
        {
            if (_cursor == _length)
            {
                _cursor = 0;
                _length = _reader.Read(_buffer);

                if (_length == 0)
                {
                    if (!_eof)
                    {
                        _eof = true;
                        return char.MinValue;
                    }
                    else
                    {
                        ThrowEndOfStreamException();
                    }
                }
            }

            return (char)_buffer[_cursor++];
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public char ReadChar()
        {
            char c;
            while (!IsValidChar(c = ReadAscii())) { }
            return c;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public string ReadString()
        {
            var builder = new StringBuilder();
            char c;
            while (!IsValidChar(c = ReadAscii())) { }

            do
            {
                builder.Append(c);
            } while (IsValidChar(c = ReadAscii()));

            return builder.ToString();
        }

        public int ReadInt() => (int)ReadLong();

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public long ReadLong()
        {
            long result = 0;
            bool isPositive = true;
            char c;

            while (!IsNumericChar(c = ReadAscii())) { }

            if (c == '-')
            {
                isPositive = false;
                c = ReadAscii();
            }

            do
            {
                result *= 10;
                result += c - '0';
            } while (IsNumericChar(c = ReadAscii()));

            return isPositive ? result : -result;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private Span<char> ReadChunk(Span<char> span)
        {
            var i = 0;
            char c;
            while (!IsValidChar(c = ReadAscii())) { }

            do
            {
                span[i++] = c;
            } while (IsValidChar(c = ReadAscii()));

            return span.Slice(0, i);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public double ReadDouble() => double.Parse(ReadChunk(stackalloc char[32]));

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public decimal ReadDecimal() => decimal.Parse(ReadChunk(stackalloc char[32]));

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

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

        public double[] ReadDoubleArray(int n)
        {
            var a = new double[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = ReadDouble();
            }
            return a;
        }

        public decimal[] ReadDecimalArray(int n)
        {
            var a = new decimal[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = ReadDecimal();
            }
            return a;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void WriteLine<T>(T value) => _writer.WriteLine(value.ToString());

        public void WriteLine<T>(IEnumerable<T> values, char separator)
        {
            var e = values.GetEnumerator();
            if (e.MoveNext())
            {
                _writer.Write(e.Current.ToString());

                while (e.MoveNext())
                {
                    _writer.Write(separator);
                    _writer.Write(e.Current.ToString());
                }
            }

            _writer.WriteLine();
        }

        public void WriteLine<T>(Span<T> values, char separator) => WriteLine((ReadOnlySpan<T>)values, separator);

        public void WriteLine<T>(ReadOnlySpan<T> values, char separator)
        {
            for (int i = 0; i < values.Length - 1; i++)
            {
                _writer.Write(values[i]);
                _writer.Write(separator);
            }

            if (values.Length > 0)
            {
                _writer.Write(values[^1]);
            }

            _writer.WriteLine();
        }

        public void Flush() => _writer.Flush();

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool IsValidChar(char c) => ValidFirstChar <= c && c <= ValidLastChar;

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool IsNumericChar(char c) => ('0' <= c && c <= '9') || c == '-';

        private void ThrowEndOfStreamException() => throw new EndOfStreamException();

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    _reader.Dispose();
                    _writer.Flush();
                    _writer.Dispose();
                }

                _disposedValue = true;
            }
        }

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

    public static class UtilExtensions
    {
        public static bool ChangeMax<T>(ref this T value, T other) where T : struct, IComparable<T>
        {
            if (value.CompareTo(other) < 0)
            {
                value = other;
                return true;
            }
            return false;
        }

        public static bool ChangeMin<T>(ref this T value, T other) where T : struct, IComparable<T>
        {
            if (value.CompareTo(other) > 0)
            {
                value = other;
                return true;
            }
            return false;
        }

        public static void SwapIfLargerThan<T>(ref this T a, ref T b) where T : struct, IComparable<T>
        {
            if (a.CompareTo(b) > 0)
            {
                (a, b) = (b, a);
            }
        }

        public static void SwapIfSmallerThan<T>(ref this T a, ref T b) where T : struct, IComparable<T>
        {
            if (a.CompareTo(b) < 0)
            {
                (a, b) = (b, a);
            }
        }

        public static void Sort<T>(this T[] array) where T : IComparable<T> => Array.Sort(array);
        public static void Sort<T>(this T[] array, Comparison<T> comparison) => Array.Sort(array, comparison);
    }

    public static class CollectionExtensions
    {
        private class ArrayWrapper<T>
        {
#pragma warning disable CS0649
            public T[] Array;
#pragma warning restore CS0649
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Span<T> AsSpan<T>(this List<T> list)
        {
            return Unsafe.As<ArrayWrapper<T>>(list).Array.AsSpan(0, list.Count);
        }

        public static void Fill<T>(this T[] array, T value) => array.AsSpan().Fill(value);
        public static void Fill<T>(this T[,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0], array.Length).Fill(value);
        public static void Fill<T>(this T[,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0], array.Length).Fill(value);
        public static void Fill<T>(this T[,,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0, 0], array.Length).Fill(value);
    }
}

#endregion