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

namespace Temp
{
    struct PointInt
    {
        public long X;

        public long Y;

        public PointInt(long x, long y)
            : this()
        {
            this.X = x;
            this.Y = y;
        }

        public static PointInt operator +(PointInt a, PointInt b)
        {
            return new PointInt(a.X + b.X, a.Y + b.Y);
        }

        public static PointInt operator -(PointInt a, PointInt b)
        {
            return new PointInt(a.X - b.X, a.Y - b.Y);
        }

        public static PointInt operator *(PointInt a, long k)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public static PointInt operator *(long k, PointInt a)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public bool IsInsideRectangle(long l, long b, long r, long t)
        {
            return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);
        }
    }

    struct LineInt
    {
        public LineInt(PointInt a, PointInt b)
            : this()
        {
            A = a.Y - b.Y;
            B = b.X - a.X;
            C = a.X * b.Y - a.Y * b.X;
        }

        public long A, B, C;

        public bool ContainsPoint(PointInt p)
        {
            return A * p.X + B * p.Y + C == 0;
        }
    }

    class MatrixInt
    {
        private long[,] m_Matrix;

        public int Size
        {
            get
            {
                return m_Matrix.GetLength(0) - 1;
            }
        }

        public long Mod { get; private set; }

        public MatrixInt(int size, long mod = 0)
        {
            m_Matrix = new long[size + 1, size + 1];
            Mod = mod;
        }

        public MatrixInt(long[,] matrix, long mod = 0)
        {
            this.m_Matrix = matrix;
            Mod = mod;
        }

        public static MatrixInt GetIdentityMatrix(int size, long mod = 0)
        {
            long[,] matrix = new long[size + 1, size + 1];

            for (int i = 1; i <= size; i++)
            {
                matrix[i, i] = 1;
            }

            return new MatrixInt(matrix, mod);
        }

        public long this[int i, int j]
        {
            get
            {
                return m_Matrix[i, j];
            }

            set
            {
                m_Matrix[i, j] = value;
            }
        }

        public static MatrixInt operator +(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);
            long[,] c = new long[n, n];
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    c[i, j] = a[i, j] + b[i, j];
                }
            }

            if (mod > 0)
            {
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= n; j++)
                    {
                        c[i, j] %= mod;
                    }
                }
            }

            return new MatrixInt(c, mod);
        }

        public static MatrixInt operator *(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);

            long[,] c = new long[n, n];

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    for (int k = 1; k <= n; k++)
                    {
                        c[i, j] += a[i, k] * b[k, j];
                        if (mod > 0)
                        {
                            c[i, j] %= mod;
                        }
                    }
                }
            }

            return new MatrixInt(c, mod);
        }
    }

    static class Algebra
    {
        public static long Phi(long n)
        {
            long result = n;
            for (long i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                    {
                        n /= i;
                    }

                    result -= result / i;
                }
            }

            if (n > 1)
            {
                result -= result / n;
            }

            return result;
        }

        public static long BinPower(long a, long n, long mod)
        {
            long result = 1;

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result = (result * a) % mod;
                }

                a = (a * a) % mod;
                n >>= 1;
            }

            return result;
        }

        public static class Permutations
        {
            public static int[] GetRandomPermutation(int n)
            {
                int[] p = new int[n];
                for (int i = 0; i < n; i++)
                {
                    p[i] = i;
                }

                Random random = new Random();
                for (int i = n - 1; i > 0; i--)
                {
                    int j = random.Next(i + 1);
                    int tmp = p[i];
                    p[i] = p[j];
                    p[j] = tmp;
                }

                return p;
            }
        }

        public static T[] Shuffle<T>(this T[] array)
        {
            int length = array.Length;
            int[] p = Permutations.GetRandomPermutation(length);
            T[] result = new T[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = array[p[i]];
            }

            return result;
        }

        public static MatrixInt MatrixBinPower(MatrixInt a, long n)
        {
            MatrixInt result = new MatrixInt(a.Size);

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result *= a;
                }

                a *= a;
                n >>= 1;
            }

            return result;
        }

        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static long ExtendedGcd(long a, long b, out long x, out long y)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                return a;
            }

            long x1;
            long y1;
            long d = ExtendedGcd(b, a % b, out x1, out y1);
            x = y1;
            y = x1 - (a / b) * y1;
            return d;
        }

        public static long Lcm(long a, long b)
        {
            return (a / Gcd(a, b)) * b;
        }

        public static bool[] GetPrimes(int n)
        {
            n = Math.Max(n, 2);
            bool[] prime = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                prime[i] = true;
            }

            for (int i = 2; i * i <= n; i++)
            {
                if (prime[i])
                {
                    if ((long)i * i <= n)
                    {
                        for (int j = i * i; j <= n; j += i)
                        {
                            prime[j] = false;
                        }
                    }
                }
            }

            return prime;
        }

        public static long GetFibonacciNumber(long n, long mod = 0)
        {
            long[,] matrix = new long[,] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 1 } };

            MatrixInt result = MatrixBinPower(new MatrixInt(matrix, mod), n);

            return result[2, 2];
        }

        public static long[] GetFibonacciSequence(int n)
        {
            long[] result = new long[n];
            result[0] = result[1] = 1;

            for (int i = 2; i < n; i++)
            {
                result[i] = result[i - 1] + result[i - 2];
            }

            return result;
        }

        public static long GetInverseElement(long a, long mod)
        {
            long x, y;
            long g = ExtendedGcd(a, mod, out x, out y);

            if (g != 1)
            {
                return -1;
            }

            return ((x % mod) + mod) % mod;
        }

        public static long[] GetAllInverseElements(long mod)
        {
            long[] result = new long[mod];
            result[1] = 1;
            for (int i = 2; i < mod; i++)
            {
                result[i] = (mod - (((mod / i) * result[mod % i]) % mod)) % mod;
            }

            return result;
        }
    }

    internal static class Reader
    {
        public static void ReadInt(out int a)
        {
            int[] number = new int[1];
            ReadInt(number);
            a = number[0];
        }

        public static void ReadInt(out int a, out int b)
        {
            int[] numbers = new int[2];
            ReadInt(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadInt(out int int1, out int int2, out int int3)
        {
            int[] numbers = new int[3];
            ReadInt(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
        }

        public static void ReadInt(out int int1, out int int2, out int int3, out int int4)
        {
            int[] numbers = new int[4];
            ReadInt(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
            int4 = numbers[3];
        }

        public static void ReadLong(out long a)
        {
            long[] number = new long[1];
            ReadLong(number);
            a = number[0];
        }

        public static void ReadLong(out long a, out long b)
        {
            long[] numbers = new long[2];
            ReadLong(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadLong(out long int1, out long int2, out long int3)
        {
            long[] numbers = new long[3];
            ReadLong(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
        }

        public static void ReadLong(out long int1, out long int2, out long int3, out long int4)
        {
            long[] numbers = new long[4];
            ReadLong(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
            int4 = numbers[3];
        }

        public static void ReadInt(int[] numbers)
        {
            // ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
            // ReSharper restore PossibleNullReferenceException

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = int.Parse(list[i]);
            }
        }

        public static int[] ReadDigits()
        {
            // ReSharper disable AssignNullToNotNullAttribute
            return Console.ReadLine().Select(x => int.Parse(x.ToString())).ToArray();
            // ReSharper restore AssignNullToNotNullAttribute
        }

        public static void ReadLong(long[] numbers)
        {
            // ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
            // ReSharper restore PossibleNullReferenceException

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = long.Parse(list[i]);
            }
        }

        public static void ReadDouble(double[] numbers)
        {
            // ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
            // ReSharper restore PossibleNullReferenceException

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = double.Parse(list[i]);
            }
        }

        public static void ReadDouble(out double a, out double b)
        {
            double[] numbers = new double[2];
            ReadDouble(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadDouble(out double int1, out double int2, out double int3)
        {
            double[] numbers = new double[3];
            ReadDouble(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
        }

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

    static class MyMath
    {
        public static int GetMinimalPrimeDivisor(int n)
        {
            for (int i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    return i;
                }
            }

            return n;
        }

        public static long Sqr(long x)
        {
            return x * x;
        }
    }

    public interface IGraph
    {
        int Vertices  { get; set; }

        IList<int> this[int i] { get; }

        void AddEdge(int u, int v);

        void AddOrientedEdge(int u, int v);
    }

    public class Graph : IGraph
    {
        private List<int>[] m_Edges;

        public int Vertices { get; set; }

        public IList<int> this[int i]
        {
            get
            {
                return this.m_Edges[i];
            }
        }

        public Graph(int vertices)
        {
            this.Vertices = vertices;

            this.m_Edges = new List<int>[vertices];

            for (int i = 0; i < vertices; i++)
            {
                this.m_Edges[i] = new List<int>();
            }
        }

        public void AddEdge(int u, int v)
        {
            this.AddOrientedEdge(u, v);
            this.AddOrientedEdge(v, u);
        }

        public void AddOrientedEdge(int first, int second)
        {
            this.m_Edges[first].Add(second);
        }

        public int[] Bfs(int start)
        {
            int[] d = new int[Vertices];
            for (int i = 0; i < Vertices; i++)
            {
                d[i] = -1;
            }

            Queue<int> queue = new Queue<int>();
            queue.Enqueue(start);
            d[start] = 0;

            while (queue.Count > 0)
            {
                int v = queue.Dequeue();
                foreach (int t in this.m_Edges[v].Where(t => d[t] == -1))
                {
                    queue.Enqueue(t);
                    d[t] = d[v] + 1;
                }
            }

            return d;
        }
    }

    class SimpleSumTable
    {
        private readonly int[,] m_Sum;

        public SimpleSumTable(int n, int m, int[,] table)
        {
            m_Sum = new int[n + 1, m + 1];

            for (int i = 1; i < n + 1; i++)
            {
                for (int j = 1; j < m + 1; j++)
                {
                    m_Sum[i, j] = m_Sum[i, j - 1] + m_Sum[i - 1, j] - m_Sum[i - 1, j - 1] + table[i, j];
                }
            }
        }

        public int GetSum(int l, int b, int r, int t)
        {
            return m_Sum[r, t] - m_Sum[r, b] - m_Sum[l, t] + m_Sum[l, b];
        }
    }

    class SegmentTreeSimpleInt<T>
    {
        public int Size { get; private set; }

        private readonly T[] m_Tree;

        private Func<T, T, T> m_Operation;

        private T m_Null;

        public SegmentTreeSimpleInt(int size, Func<T, T, T> operation, T nullElement, IList<T> array = null)
        {
            this.Size = size;
            this.m_Operation = operation;
            this.m_Null = nullElement;

            m_Tree = new T[4 * size];
            if (array != null)
            {
                this.Build(array, 1, 0, size - 1);
            }
        }

        private void Build(IList<T> array, int v, int tl, int tr)
        {
            if (tl == tr)
            {
                m_Tree[v] = array[tl];
            }
            else
            {
                int tm = (tl + tr) / 2;
                this.Build(array, 2 * v, tl, tm);
                this.Build(array, 2 * v + 1, tm + 1, tr);
                this.CalculateNode(v);
            }
        }

        public T GetSum(int l, int r)
        {
            return GetSum(1, 0, Size - 1, l, r);
        }

        private T GetSum(int v, int tl, int tr, int l, int r)
        {
            if (l > r)
            {
                return m_Null;
            }

            if (l == tl && r == tr)
            {
                return m_Tree[v];
            }

            int tm = (tl + tr) / 2;

            return this.m_Operation(GetSum(2 * v, tl, tm, l, Math.Min(r, tm)),GetSum(2 * v + 1, tm + 1, tr, Math.Max(l, tm + 1), r));
        }

        public void Update(int pos, T newValue)
        {
            Update(1, 0, Size - 1, pos, newValue);
        }

        private void Update(int v, int tl, int tr, int pos, T newValue)
        {
            if (tl == tr)
            {
                m_Tree[v] = newValue;
            }
            else
            {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                {
                    Update(2 * v, tl, tm, pos, newValue);
                }
                else
                {
                    Update(2 * v + 1, tm + 1, tr, pos, newValue);
                }
                this.CalculateNode(v);
            }
        }

        private void CalculateNode(int v)
        {
            m_Tree[v] = this.m_Operation(m_Tree[2 * v], m_Tree[2 * v + 1]);
        }
    }

    struct Pair<TFirst, TSecond>
    {
        public Pair(TFirst first, TSecond second)
            : this()
        {
            this.First = first;
            this.Second = second;
        }

        public TFirst First { set; get; }

        public TSecond Second { set; get; }
    }

    internal class AccumulativeDictionary<TKey> : Dictionary<TKey, int>
    {
        public new void Add(TKey key, int value = 1)
        {
            if (this.ContainsKey(key))
            {
                base[key] += value;
            }
            else
            {
                base.Add(key, value);
            }
        }

        public new int this[TKey key]
        {
            get
            {
                return this.ContainsKey(key) ? base[key] : 0;
            }
            set
            {
                this.Add(key, value);
            }
        }
    }

    class PriorityQueue<T>
    {
        public PriorityQueue(Comparison<T> comparison = null)
        {
            if (comparison == null)
            {
                if (typeof(T).GetInterfaces().Any(i => i == typeof(IComparable<T>)))
                {
                    m_Comparison = (a, b) => ((IComparable<T>)a).CompareTo(b);
                }
                else
                {
                    throw new ApplicationException("Add comparer");
                }
            }
            else
            {
                m_Comparison = comparison;
            }
        }

        public int Count { get; private set; }

        public void Enqueue(T item)
        {
            if (m_Indexes.ContainsKey(item))
            {
                this.Update(item);
            }
            else
            {
                m_List.Add(item);
                m_Indexes.Add(item, this.Count);
                this.Count++;
                Up(this.Count);
            }
        }

        public T Peek()
        {
            return m_List[0];
        }

        public T Dequeue()
        {
            if (this.Count > 0)
            {
                var result = m_List[0];

                Swap(0, this.Count - 1);
                this.RemoveLast();
                this.Down(1);

                return result;
            }
            throw new ApplicationException("Couldn't get element from empty queue");
        }

        public void Update(T item)
        {
            int index = m_Indexes[item];
            this.Up(index + 1);
        }

        public void Remove(T item)
        {
            if (m_Indexes.ContainsKey(item))
            {
                int index = m_Indexes[item];

                this.Swap(index, this.Count - 1);

                this.RemoveLast();
            }
        }

        private readonly List<T> m_List = new List<T>();

        private readonly Dictionary<T, int> m_Indexes = new Dictionary<T,int>();

        private readonly Comparison<T> m_Comparison;

        private int Up(int index)
        {
            while (index > 1 && m_Comparison.Invoke(m_List[index - 1], m_List[index / 2 - 1]) < 0)
            {
                this.Swap(index - 1, index / 2 - 1);

                index = index / 2;
            }

            return index;
        }

        private int Down(int index)
        {
            while (2 * index <= this.Count && m_Comparison.Invoke(m_List[index - 1], m_List[2 * index - 1]) > 0 ||
                   2 * index + 1 <= this.Count && m_Comparison.Invoke(m_List[index - 1], m_List[2 * index]) > 0)
            {
                if (2 * index + 1 > this.Count || m_Comparison.Invoke(m_List[2 * index - 1], m_List[2 * index]) < 0)
                {
                    this.Swap(index - 1, 2 * index - 1);
                    index = 2 * index;
                }
                else
                {
                    this.Swap(index - 1, 2 * index);
                    index = 2 * index + 1;
                }
            }

            return index;
        }

        private void Swap(int i, int j)
        {
            var tmp = m_List[i];
            m_List[i] = m_List[j];
            m_List[j] = tmp;

            m_Indexes[m_List[i]] = i;
            m_Indexes[m_List[j]] = j;
        }

        private void RemoveLast()
        {
            m_Indexes.Remove(m_List[this.Count - 1]);
            m_List.RemoveAt(this.Count - 1);
            this.Count--;
        }
    }

    class Program
    {
        private static StreamReader m_InputStream;

        private static StreamWriter m_OutStream;

        private static void OpenFiles()
        {
            m_InputStream = File.OpenText("input.txt");
            Console.SetIn(m_InputStream);

            m_OutStream = File.CreateText("output.txt");
            Console.SetOut(m_OutStream);
        }

        private static void CloseFiles()
        {
            m_OutStream.Flush();

            m_InputStream.Dispose();
            m_OutStream.Dispose();
        }

        static void Main()
        {
           // OpenFiles();

            new Solution().Solve();

           // CloseFiles();
        }
    }

    internal class Solution
    {
        public void Solve()
        {
            long p, d;
            Reader.ReadLong(out p, out d);

            long m = p - d;

            string aa = p.ToString();
            string bb = m.ToString();
            while (bb.Length < aa.Length)
            {
                bb = "0" + bb;
            }

            char[] a = new char[aa.Length];
            for (int i = 0; i < aa.Length; i++)
            {
                a[i] = aa[i];
            }

            char[] b = new char[aa.Length];
            for (int i = 0; i < aa.Length; i++)
            {
                b[i] = bb[i];
            }

            for (int i = 0; i < a.Length - 1; i++)
            {
                if (a[i] > b[i])
                {
                    bool ok = false;
                    for (int j = i + 1; j < a.Length; j++)
                    {
                        if (a[j] != '9')
                        {
                            ok = true;
                        }
                    }

                    if (!ok)
                    {
                        Console.WriteLine(p);
                        return;
                    }

                    b[i] = (char)(a[i] - 1);
                    for (int j = i + 1; j < a.Length; j++)
                    {
                        b[j] = '9';
                    }
                    string s = "";
                    for (int j = 0; j < aa.Length; j++)
                    {
                        s = s + b[j];
                    }

                    Console.WriteLine(long.Parse(s));
                    return;
                }
            }

            Console.WriteLine(p);
        }
    }
}


using System;
namespace Iran{
        class amir
        {
                public static void Main()
                {
                        int x,y,s;
                        string[] input=Console.ReadLine().Split(' ');
                        x=Int32.Parse(input[0]);
                        y=Int32.Parse(input[1]);
                        s=Int32.Parse(input[2]);
                        long yek,dow;
                        if(x%s==0)
                                yek=x;
                        else
                        {
                                yek=(x%s)*(x/s+1);
                        }
                        if(y%s==0)
                                dow=y;
                        else
                        {
                                dow=(y%s)*(y/s+1);
                        }
                        long ans=dow*yek;
                        Console.WriteLine(ans);

                }
        }
}


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

class Program
{

    void solve()
    {
        long n = nextInt();
        long m = nextInt();
        long s = nextInt();
        long res = get(n, s);
        res *= get(m, s);
        println(res);
    }

    private long get(long n, long s)
    {
        long most = (n - 1) / s;
        int res = 0;
        for (int i = 0; i < n; i++)
        {
            long cur = (n - 1 - i) / s;
            cur += i / s;
            if (cur == most)
                res++;
        }
        return res;
    }

    ////////////
    private void println(int[] ar)
    {
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i]);
            else
                print(ar[i] + " ");
        }
    }
    private void println(int[] ar, bool add)
    {
        int A = 0;
        if (add)
            A++;
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i] + A);
            else
                print((ar[i] + A) + " ");
        }
    }

    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        new Program().solve();
    }
}


//

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

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

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

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

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

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

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

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

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

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

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

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

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

            public bool EOF
            {
                get
                {
                    if (Read() == -1) return true;
                    Back();
                    return false;
                }
            }

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

        static void pe()
        {
            Console.WriteLine("???");
            Environment.Exit(0);
        }

        static void re()
        {
            Environment.Exit(55);
        }

        static int nosol()
        {
            Console.WriteLine("ERROR");
            return 0;
        }

        static Stopwatch sw = Stopwatch.StartNew();

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

        static void Swap<T>(ref T a, ref T b)
        {
            T t = a;
            a = b;
            b = t;
        }

        static int n;
        static int[] j = new int[6];
        static int[,] l = new int[6, 6];
        static int[,] h = new int[6, 6];
        static int[,] a = new int[6, 6];
        static int[,] flow = new int[6, 6];

        static int resultFlow;
        static int resultCost;

        static void per(int v, int w, int q)
        {
            if (q < 0) throw new Exception();

            int j_bak = j[w];

            if (w == n - 1)
            {
                if (q >= l[v, w] && q <= h[v, w])
                {
                    flow[v, w] = q;
                    j[w] = j_bak + q;
                    visit(v + 1);
                }
            }
            else
            {
                for (int i = l[v, w]; i <= h[v, w]; i++)
                {
                    if (i > q) break;
                    if (q - i > 5 * (n - 1 - w)) continue;
                    flow[v, w] = i;
                    j[w] = j_bak + i;
                    per(v, w + 1, q - i);
                }
            }

            flow[v, w] = 0;
            j[w] = j_bak;
        }

        static void visit(int v)
        {
            if (v == n - 1)
            {
                if (j[n - 1] != j[0]) throw new Exception();
                if (j[n - 1] <= resultFlow)
                {
                    int cost = 0;
                    for (v = 0; v < n; v++)
                        for (int w = v + 1; w < n; w++)
                            if (flow[v, w] > 0) cost += a[v, w] + flow[v, w] * flow[v, w];
                    if (j[n - 1] < resultFlow || cost > resultCost) resultCost = cost;
                    resultFlow = j[n - 1];
                }
            }
            else
            {
                per(v, v + 1, j[v]);
            }
        }

        static int Main(string[] args)
        {
            //Console.SetIn(File.OpenText("_input"));
            Parser parser = new Parser();
            while (!parser.SeekEOF)
            {
                n = parser.ReadInt();
                for (int i = 0; i < n * (n - 1) / 2; i++)
                {
                    int v = parser.ReadInt() - 1;
                    int w = parser.ReadInt() - 1;
                    l[v, w] = parser.ReadInt();
                    h[v, w] = parser.ReadInt();
                    a[v, w] = parser.ReadInt();
                }

                resultFlow = int.MaxValue;
                resultCost = 0;
                for (j[0] = 0; j[0] <= 25; j[0]++)
                    visit(0);

                if (resultFlow == int.MaxValue) resultFlow = resultCost = -1;
                Console.WriteLine(resultFlow + " " + resultCost);
            }

            return 0;
        }
    }
}


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

namespace ProgrammingContest.Codeforces.Round62
{
    class C
    {
        static int n;
        static int[] fuel;
        static List<int[]>[] xs;
        static int f,c;

        static void chk(int cost)
        {
            if (fuel[n - 1] < 0) return;
            if (f == fuel[n - 1] && c < cost) { c = cost; }
            if (f == -1 || f > fuel[n - 1]) { f = fuel[n - 1]; c = cost; }
        }

        static void dfs(int i, int j, int cost)
        {
            if (i >= n - 1) { chk(cost); return; }
            if (i == 1 && j == 0 && f != -1 && f < -fuel[0])
                return;
            if (j >= xs[i].Count)
            {
                if (i == 0 || fuel[i] == 0)
                    dfs(i + 1, 0, cost);
                return;
            }

            int dst = xs[i][j][1];
            for (int k = xs[i][j][2]; k <= xs[i][j][3]; k++)
                if (i == 0 || k <= fuel[i])
                {
                    fuel[i] -= k;
                    fuel[dst] += k;

                    int nc = k == 0 ? cost : (cost + k * k + xs[i][j][4]);
                    dfs(i, j + 1, nc);

                    fuel[dst] -= k;
                    fuel[i] += k;
                }
        }

        public static void Main()
        {
            n = int.Parse(Console.ReadLine());
            xs = new List<int[]>[n];
            fuel = new int[n];
            for (int i = 0; i < n; i++)
                xs[i] = new List<int[]>();
            for (int i = 0; i < n * (n - 1) / 2; i++)
            {
                var ys = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
                ys[0]--; ys[1]--;
                xs[ys[0]].Add(ys);
            }
            f = -1; c = -1;
            dfs(0, 0, 0);
            Console.WriteLine("{0} {1}", f, c);
        }
    }
}


using System;

namespace CodeForces
{
	public class A
	{
		static void Main()
		{
			var n = int.Parse( Console.ReadLine() );
			if ( n == 1 )
			{
				Console.WriteLine( 0 );
				return;
			}
			int res = int.MaxValue;
			for ( int i = 1; i < n; ++i )
			{
				var x = i;
				var cur = 0;
				var y = n;
				while ( x > 0 && y > 0 )
				{
					if ( x > y )
					{
						cur += x / y;
						x %= y;
					}
					else
					{
						cur += y / x;
						y %= x;
					}
				}
				if ( x + y == 1 )
					res = Math.Min( res, cur );
			}
			Console.WriteLine( res - 1 );
		}
	}
}


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

namespace CodeForces
{
	public class A
	{
		static void Main()
		{
			var n = int.Parse( Console.ReadLine() );
			if ( n == 1 )
			{
				Console.WriteLine( 0 );
				return;
			}
			var lst = new List<int>();
			var res = int.MaxValue;
			for ( var i = 1; i < n; ++i )
			{
				lst.Add( i );
				var x = i;
				var cur = 0;
				var y = n;
				while ( x > 0 && y > 0 )
				{
					if ( x > y )
					{
						cur += x / y;
						x %= y;
					}
					else
					{
						cur += y / x;
						y %= x;
					}
				}
				if ( x + y == 1 )
					res = Math.Min( res, cur );
			}

			var test = lst.Where( x => x % 5 == 1 ).OrderBy( x => x % 10 ).Take( 4 );

			if ( test.Any( x => x == res ) )
			{
				Console.WriteLine( res - 1 );
			}
			else
			{
				Console.WriteLine( res - 1 );
			}
		}
	}
}


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

namespace My_pretty_girl_Noora
{
    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 t = Next();
            int l = Next();
            int r = Next();

            var nn = new long[r + 1];
            for (int i = 2; i < nn.Length; i++)
            {
                nn[i] = long.MaxValue;
            }
            nn[1] = 1;
            for (long i = 2; i < nn.Length; i++)
            {
                nn[i] = Math.Min(nn[i], i*(i - 1)/2);

                long max = Math.Min(i*i, r);
                long y = 2;
                for (long j = i + i; j <= max; j += i, y++)
                {
                    var tt = nn[i] + i*nn[y];
                    if (nn[j] > tt)
                        nn[j] = tt;
                    //nn[j] = Math.Min(nn[j], nn[i] + i*nn[y]);
                }
            }

            long sum = 0;
            long k = 1;
            int mod = 1000000007;

            for (int i = l; i <= r; i++)
            {
                sum = (sum + k*(nn[i]%mod))%mod;
                k = (k*t)%mod;
            }

            writer.WriteLine(sum);
            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 System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            long intPart = (long)valueToWrite;
            double fracPart = valueToWrite - intPart;
            var fracPartStr = fracPart.ToString();
            if (fracPartStr.Length > 1)
                fracPartStr = fracPartStr.Substring(2);
            var strToWrite = string.Format("{0}.{1}", intPart, fracPartStr);
            writer.WriteLine(strToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int t;
        int l, r;

        int prime = 1000000007;

        long[] ans;

        List<int> primes = new List<int>();

        int primeLimit;

        bool IsPrime(int i)
        {
            foreach(var prime in primes)
            {
                if (prime * prime > i)
                    return true;

                if (i % prime == 0)
                    return false;
            }

            return true;
        }

        public void Solve()
        {
            t = ioHelper.ReadNextInt();
            l = ioHelper.ReadNextInt();
            r = ioHelper.ReadNextInt();

            // n = p0 * p1 *  ... * pk. pi = numar prim. p[i+1]>=p[i].
            // R = n/2 * ( (p0-1) + (p1-1)/p0 + (p2-1)/(p0*p1) + (p3-1)/(p0*p1*p2) + ... ).

            primeLimit = (int)Math.Ceiling(Math.Sqrt(r)+1);

            ans = new long[r+1];

            ans[0] = 0;
            ans[1] = 0;

            int i, j;

            primes.Add(2);

            for (i = 3; i <= primeLimit; i++)
                if (IsPrime(i))
                    primes.Add(i);

            for (i = primeLimit + 1; i <= r; i++)
                if (IsPrime(i))
                    ans[i] = (i * (long)(i - 1) / 2) % prime;

            for (j = primes.Count - 1; j >= 0; j--)
                for (i = 1; i * primes[j] <= r; i++)
                    if (ans[i] > 0 || i==1)
                    {
                        var p = primes[j];
                        var n = i * p;

                        long rz = n * (long)(p - 1) / 2;
                        rz += ans[i];

                        rz %= prime;

                        ans[n] = rz;
                    }

            long coeff = 1;
            long rez = 0;

            for(i=l;i<=r;i++)
            {
                if (ans[i] == 0)
                    ans[i] = i * (long)(i - 1) / 2;

                ans[i] %= prime;

                rez += (ans[i] * coeff) % prime;

                rez %= prime;

                coeff *= t;
                coeff %= prime;
            }

            ioHelper.WriteLine(rez.ToString());
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}


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

namespace A.Theatre_Square
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] data = Console.ReadLine().Split(' ');
            int n = Int32.Parse(data[0]);
            int m = Int32.Parse(data[1]);
            int k = Int32.Parse(data[2]);
            if (n % 2 == 0)
            {
                Console.WriteLine("Marsel");
                return;
            }

            if (n % 2 == 1)
            {
                if (k == 1 && m!=1)
                {
                    Console.WriteLine("Timur");
                    return;
                }
                for (int i = 2; i * i <= m; i++)
                {
                    if (m % i == 0 && (m / i >= k || i >= k ) )
                    {
                        Console.WriteLine("Timur");
                        return ;
                    }
                }
            }

            Console.WriteLine("Marsel");

            Console.ReadKey();
        }

    }
}


using System;
using System.Text;

namespace CodeForces
{
    class Program
    {
        public static bool IsPrim(int n, int k)
        {
            if(k == 1)
                return false;

            if(n==2 && k <=2)
                return true;

            for (int i = 2; i <= Math.Sqrt(n); i++)
                if (n % i == 0 && (i >= k ||  n / i >= k))
                    return false;
            return true;
        }
        static void Main()
        {
            var input = Console.ReadLine().Split(' ');
            var n = Int32.Parse(input[0]);
            var m = Int32.Parse(input[1]);
            var k = Int32.Parse(input[2]);

            if (m < 2 * k || n % 2 == 0 || IsPrim(m, k))
            {
                Console.WriteLine("Marsel");
                return;
            }
            Console.WriteLine("Timur");
        }
    }
}


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

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

	internal class Task
	{
		public void Solve(int testNumber, InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int32.Parse);
			var a = input[0];
			var ta = input[1];
			input = sr.ReadArray(Int32.Parse);
			var b = input[0];
			var tb = input[1];
			var str = sr.NextString().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
			var h = str[0][0] == '0' ? Int32.Parse(str[0][1].ToString(CultureInfo.InvariantCulture)) : Int32.Parse(str[0]);
			var m = str[1][0] == '0' ? Int32.Parse(str[1][1].ToString(CultureInfo.InvariantCulture)) : Int32.Parse(str[1]);
			var count = 0;
			var start = h * 60 + m;
			int end =start + ta;
			var bArr = new List<Tuple<int, int>>();
			for (var startB = 5 * 60; startB <= 23*60 + 59; startB += b) {
				bArr.Add(new Tuple<int, int>(startB, startB + tb));
			}
			for (var i = 0; i < bArr.Count; i++) {
				var next = bArr[i];
				if (start < next.Item2 && next.Item1 < end) {
					count++;
				}
			}

			sw.WriteLine(count);
		}
	}

	internal class InputReader : IDisposable
	{
		private bool isDispose;
		private readonly TextReader sr;

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

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

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

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

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

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

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

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

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

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


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

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

            string[] t_A = Console.ReadLine().Split(' ');
            string[] t_B = Console.ReadLine().Split(' ');
            string[] HHH = Console.ReadLine().Split(':');
            int hour = 0;
            if (HHH[0][0] == '0') hour = int.Parse(HHH[0][1].ToString());
            else
                hour = int.Parse(HHH[0][0].ToString()) * 10 + int.Parse(HHH[0][1].ToString());
            int minute = 0;
            if (HHH[1][0] == '0') minute = int.Parse(HHH[1][1].ToString());
            else
                minute = int.Parse(HHH[1][0].ToString()) * 10 + int.Parse(HHH[1][1].ToString());
            int starttime = hour * 60 + minute;
            int endtime = starttime + int.Parse(t_A[1].ToString());
            int ans = 0;
            int start = 300;
            int chastota = int.Parse(t_B[0].ToString());
            int time = int.Parse(t_B[1].ToString());
            while (true)
            {
                if (start >= endtime || start > 1439) break;
                if (start + time > starttime)
                {
                    ans++;
                }
                start += chastota;
            }

            Console.WriteLine(ans);

        }
    }
}


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

namespace Crunching_Numbers_Just_for_You
{
    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 n = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            Array.Sort(nn);

            List<string> s = nn.Select(t => t.ToString()).ToList();

            DateTime next = DateTime.UtcNow.AddSeconds(1);
            long k = 1;
            while (DateTime.UtcNow<next)
            {
                k++;
            }

            foreach (string c in s)
            {
                writer.Write(c);
                writer.Write(' ');
            }
            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 System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Solution
{

    static void Main(String[] args)
    {
        Stopwatch e = new Stopwatch();
        e.Start();
        var n = Console.ReadLine().Split().Skip(1).Select(int.Parse).ToList();
        n.Sort();
        while (e.ElapsedMilliseconds < 1400)
        {

        }
        Console.WriteLine(string.Join(" ", n));
        Console.Read();
    }
}


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

namespace Codeforces
{

    /*

string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            string tt = Console.ReadLine();
            int[] a = tt.Split(' ').Select(q => Convert.ToInt32(q)).ToArray();
            int[] k = Enumerable.Repeat(0, n).ToArray();
            Array.Sort<int>(a,
                    new Comparison<int>(
                            (i1, i2) => i2.CompareTo(i1)
                    ));
 */

 /*

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

            string t = Console.ReadLine();
            int[] a = t.Split(' ').Select(q => Convert.ToInt32(q)).ToArray();
  */
    class B
    {
        private static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = int.Parse(input);
            int res = 0;
            int k = (int)Math.Sqrt(n);
            int t = k * k;
            if (n - t > k)
                res = (k + 1) * 2;
            else if (t == n)
                res = k * 2;
            else
                res = k * 2 + 1;
            Console.WriteLine(res);
        }
    }
}


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

namespace Yuhao
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int sqr = (int)Math.Sqrt(n);
            if (sqr * sqr < n) sqr++;
            int X;
            X = 2 * sqr;
            if (sqr * (sqr - 1) >= n)
                X--;

            Console.WriteLine(X);

   //   Console.ReadKey();

        }
    }
}


/*

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

    /// <summary>
    /// Keep track of tree size and take steps to avoid having tall trees.
    /// Smaller tree will connect to the root of the larger tree.
    /// Java implementation on p. 228
    /// Depth of any node x is at most lg N (lg = base-2 logarithms)
    /// If N is 1,000 its 10 (2^10 = 1000)
    /// If N is 1,000,000 its 20 (2^20)
    /// If N is 1,000,000,000 its 30 (2^30)
    /// Can also add path compression: just after computing root of p,
    /// set the id of each examined node to point to that root
    /// </summary>
    public class QuickUnionUF2 // Weighted Quick Union
    {
        private int[] id;
        private int[] sz;
        private int count; // number of components

        public QuickUnionUF2(int N)
        {
            id = new int[N];
            for (int i = 0; i < N; i++) id[i] = i;

            sz = new int[N];
            for (int i = 0; i < N; i++) sz[i] = 1;
            count = N;
        }

        public int Count() { return count;  }

        private int Root(int i)
        {
            // Chase parent ID until reach the root (depth of i array accesses)
            while (i != id[i])
            {
                // Halves path length. No reason not to, keeps tree almost completely flat.
                id[i] = id[id[i]]; // Only 1 extra line of code to do path compression improvement!

                i = id[i];
            }
            return i;
        }

        public bool Connected(int p, int q) // Find
        {
            return Root(p) == Root(q);
        }

        public void Union(int p, int q)
        {
            int i = Root(p);
            int j = Root(q);

            if (i == j) return;

            // Make smaller root point to the larger root.
            if (sz[i] < sz[j]) // if i is smaller than j
            {
                id[i] = j; // point i to new root j
                sz[j] += sz[i]; // add the count of the smaller array to the count of the larger array
            }
            else // if j is smaller than i
            {
                id[j] = i;
                sz[i] += sz[j];
            }

            count--; // if we combine components, the count of components goes down by 1
        }
    }

public class Solver
{
    public IEnumerable<int> Factor(int number) {
        int max = (int)Math.Sqrt(number);  //round down
        for(int factor = 2; factor <= max; ++factor) { //test from 1 to the square root, or the int below it, inclusive.
            if(number % factor == 0) {
                yield return factor;
                if(factor != number/factor) { // Don't add the square root twice!  Thanks Jon
                    yield return number/factor;
                }
            }
        }
    }

    public void Solve()
    {
        /*
         * a - b = c    a = c + b
         * n % c == 0
         */
        long n = ReadLong();

        var primes = new Dictionary<long,int>();
        long nn = n;
        long x = 2;
        while (1 < nn && x * x <= n)
        {
            while (nn % x == 0)
            {
                if (!primes.ContainsKey(x))
                    primes[x] = 0;
                primes[x]++;
                nn /= x;
            }
            x++;
        }
        if (1 < nn)
            primes[nn] = 1;

        if (primes.Count() == 1)
            Write(primes.First().Key);
        else if (!primes.Any())
            Write(n);
        else
            Write(1);

    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
        Debug.Listeners.Clear();
        Debug.Listeners.Add(new ConsoleTraceListener());
        Trace.Listeners.Clear();
        Trace.Listeners.Add(new ConsoleTraceListener());

        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        new Solver().Solve();
        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.Linq;
using System.Text;

class A
{
    public static List<long> GetDivisors(long n)
    {

        // Note that this loop runs
        // till square root
        var list = new List<long>();
        for (long i = 1; i <= Math.Sqrt(n); i++)
        {
            if (n % i == 0)
            {
                // If divisors are equal,
                // print only one
                if (n / i == i)
                {
                    list.Add(i);
                }
                else
                {
                    list.Add(i);
                    list.Add(n / i);
                }
            }
        }
        return list;
    }

    public static long GCD(long a, long b)
    {
        if (b == 0)
        {
            return a;
        }

        return GCD(b, a % b);
    }
    public static void Main(string[] args)
    {
        int t = 1;
        while (t > 0)
        {
            var n = long.Parse(Console.ReadLine());
            var div = GetDivisors(n);
            if (div.Count <= 2)
                Console.WriteLine(n);
            else
            {
                var sorted = div.OrderBy(x => x).ToArray();
                var ans = sorted[1];
                for (int i = 2; i < sorted.Count(); i++)
                {
                    ans = GCD(ans, sorted[i]);
                }
                Console.WriteLine(ans);
            }
            t--;
        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var str = Console.ReadLine();
            var s = str.ToList();

            var a = new int[s.Count, s.Count];
            var res = tutu(a, s, 0, s.Count - 1);
            Console.WriteLine(res);
        }

        // tutu(a, s, 0, s.Count - 1)
        static int tutu(int[,] a, List<char> s, int from, int to)
        {
            if (a[from, to] == 0)
            {
                if (from == to)
                    return 1;
                var res = int.MaxValue;

                if (s[from] == s[to])
                {
                    res = tutu(a, s, from + 1, to);
                }
                else
                {
                    for (int i = from; i < to; i++)
                    {
                        var z = tutu(a, s, from, i) + tutu(a, s, i + 1, to);
                        if (s[from] == s[i + 1] || s[i] == s[to])
                            z--;
                        res = Math.Min(res, z);
                    }
                }
                a[from, to] = res;
            }
            return a[from, to];
        }

    }
}


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

public class HelloWorld {

    static int n;
    static int m;
    static int[] str;
    static int[,,] memo;
    static int[,] memoSol;

    public static void SolveCodeForces() {
        Console.ReadLine();
        str = Console.ReadLine().Select(c => c - 'a').ToArray();
        n = str.Length;
        m = str.Max()+1;

        memo = new int[n, n, m];
        for (var i = 0; i < n; i++)
            for (var j = 0; j < n; j++)
                for (var k = 0; k < m; k++)
                    memo[i,j,k] = -1;

        memoSol = new int[n, n];
        for (var i = 0; i < n; i++)
            for (var j = 0; j < n; j++)
                memoSol[i,j] = -1;

        System.Console.WriteLine(Solve(0, n-1));
    }

    static int Solve(int i, int j) {
        if (i > j) return 0;
        if (i == j) return 1;
        if (memoSol[i, j] >= 0) return memoSol[i, j];

        var ans = 10000;
        for (var sym = 0; sym < m; sym++)
            ans = Math.Min(ans, SolveFun(i, j, sym));
        ans++;
        memoSol[i, j] = ans;
        return ans;
    }

    static int SolveFun(int i, int j, int sym) {
        if (i > j) return 0;
        if (i == j) return str[i] == sym ? 0 : 10000;
        if (memo[i,j,sym] >= 0) return memo[i,j,sym];

        var ans = 10000;

        for (var k = i; k <= j; k++) {
            if (str[k] == sym) {

                var fl = SolveFun(i, k-1, sym);
                var sl = Solve(i, k-1);

                var fr = SolveFun(k+1, j, sym);
                var sr = Solve(k+1, j);

                var sol =
                    Math.Min(fl + fr,
                    Math.Min(sl + sr,
                    Math.Min(fl + sr,
                             sl + fr)));

                ans = Math.Min(ans, sol);
            }
        }

// System.Console.WriteLine(new { i, j, sym, ans });

        memo[i, j, sym] = ans;
        return ans;
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


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

namespace ConsoleApplication4
{
    class Program
    {
        struct Matrix
        {
            public long A1, A2, A3, A4;

            public static Matrix Mul(Matrix m1, Matrix m2)
            {
                Matrix result = new Matrix();
                result.A1 = m1.A1 * m2.A1 + m1.A2 * m2.A3;
                result.A2 = m1.A1 * m2.A2 + m1.A2 * m2.A4;
                result.A3 = m1.A3 * m2.A1 + m1.A4 * m2.A3;
                result.A4 = m1.A3 * m2.A2 + m1.A4 * m2.A4;
                return result;
            }

            public void Mod(long mod)
            {
                A1 %= mod; A2 %= mod; A3 %= mod; A4 %= mod;
            }

            public static Matrix PowerMod(long power, Matrix m, long mod)
            {
                Matrix modLast = m, result = new Matrix();

                while (power != 0)
                {
                    if ((power & 1) == 1)
                    {
                        if (result.A1 == 0)
                            result = modLast;
                        else
                            result = Matrix.Mul(result, modLast);

                        result.Mod(mod);
                    }

                    modLast = Matrix.Mul(modLast, modLast);
                    modLast.Mod(mod);
                    power >>= 1;
                }

                return result;
            }
        }

        static void Main(string[] args)
        {
            string[] fStrings = new string[31];
            fStrings[0] = "a"; fStrings[1] = "b";

            for (int i = 2; i < fStrings.Length; i++)
                fStrings[i] = fStrings[i - 1] + fStrings[i - 2];

            string[] inputStr = Console.ReadLine().Split(' ');
            long m = Convert.ToInt64(inputStr[0]);
            int n = Convert.ToInt32(inputStr[1]);
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                long count = CalCount(s, fStrings, m - 1);
                sw.WriteLine(count % 1000000007);
            }

            sw.Flush();
        }

        static long CalCount(string s, string[] fStrings, long num)
        {
            if (num < 10)
                return ContainCount(s, fStrings[num]);

            Matrix m = new Matrix { A1 = 1, A2 = 1, A3 = 1, A4 = 0 };
            List<int> result = new List<int>();
            int index = 0;

            for (int i = 0; i < fStrings.Length; i++)
            {
                int count = ContainCount(s, fStrings[i]);
                if (count > 1)
                {
                    if(index == 0)
                        index = i;

                    result.Add(count);
                }

                if (fStrings[i].Length > s.Length * 10)
                    break;
            }

            if(result.Count == 0)
                return 0;

            index -= 2;
            Matrix power = Matrix.PowerMod(num - index + 1, m, 1000000007);

            if (result[0] == 2)
            {
                if (result[1] == 3)
                    return power.A2;
                else
                    return power.A1 - 1;
            }
            else
                return power.A1 - (num - index) % 2;
        }

        static int ContainCount(string p, string s)
        {
            if (p.Length > s.Length) return 0;
            int k = -1, count = 0;

            while (true)
            {
                k = s.IndexOf(p, k + 1);
                if (k == -1) break;
                count++;
            }

            return count;
        }
    }
}


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

namespace Codeforces.TaskE
{
    public class Task
    {
        public static void Main()
        {
            var task = new Task();
            task.Solve();
        }

        private const long Mod = 1000000007L;
        private const long Max = 102L;
        private long n, m, k;
        private long[,,,] Ways;
        private long[][] C;

        void Solve()
        {
            Input.Next(out n, out m, out k);

            C = new long[Max][];
            C[0] = new long[1];
            C[0][0] = 1;
            for (var i = 1; i < Max; i++)
            {
                C[i] = new long[i + 1];
                C[i][0] = 1; C[i][i] = 1;
                for (var j = 1; j < i; j++)
                    C[i][j] = C[i - 1][j - 1] + C[i - 1][j] % Mod;
            }

            n /= 2;
            Ways = new long[n + 2, n + 2, n + 2, Max];
            Ways[0, 1, 0, 1] = 1;

            var result = 0L;
            for (var maxValue = 0; maxValue <= n && maxValue < m; maxValue++)
                for (var holes = 0; holes <= n; holes++)
                    for (var total = 0; total <= n; total++)
                        for (var ways = 0; ways <= k; ways++)
                        {
                            var prevWays = Ways[maxValue, holes, total, ways];
                            if (prevWays == 0) continue;
                            if (maxValue > 0)
                            {
                                result += (prevWays * (m - maxValue)) % Mod;
                                result %= Mod;
                            }

                            for (var newCountOfMaxValues = 1; newCountOfMaxValues <= n - total; newCountOfMaxValues++)
                            {
                                var newWays = ways*C[holes + newCountOfMaxValues - 1][newCountOfMaxValues];
                                if (newWays <= k)
                                {
                                    Ways[maxValue + 1, newCountOfMaxValues, total + newCountOfMaxValues, newWays] += prevWays;
                                    Ways[maxValue + 1, newCountOfMaxValues, total + newCountOfMaxValues, newWays] %= Mod;
                                }
                            }
                        }
            Console.WriteLine(result);
        }
    }

    #region Input

    public class Input
    {
        private static string _line;

        public static bool Next()
        {
            _line = Console.ReadLine();
            return !string.IsNullOrEmpty(_line);
        }

        public static bool Next(out long a)
        {
            var ok = Next();
            a = ok ? long.Parse(_line) : 0;
            return ok;
        }

        public static bool Next(out long a, out long b)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
            }
            else
            {
                a = b = 0;
            }

            return ok;
        }

        public static bool Next(out long a, out long b, out long c)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
            }
            else
            {
                a = b = c = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
            }
            else
            {
                a = b = c = d = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d, out long e)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
            }
            else
            {
                a = b = c = d = e = 0;
            }
            return ok;
        }

        public static List<long> Numbers()
        {
            Next();
            return _line.Split(' ').Select(long.Parse).ToList();
        }
    }

    #endregion

}


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

class Solver
{
    public void Solve(Scanner sc)
    {
        long N, M, L, R;
        sc.Make(out N, out M, out L, out R);
        R -= L;
        if (N * M % 2 == 1)
        {
            Fail(ModInt.Pow(R + 1, N * M));
        }
        ModInt odd = (R + 1) / 2, even = R / 2 + 1;
        var A = new[] { new[] { even, odd }, new[] { odd, even } };
        var f = N * M;
        var res = new[] { new[] { (ModInt)1, 0 }, new[] { (ModInt)0, 1 } };
        while (f != 0)
        {
            if (f % 2 == 1) res = matmul(res, A);
            f >>= 1;
            A = matmul(A, A);
        }
        WriteLine(res[0][0]);
    }
    ModInt[][] matmul(ModInt[][] A,ModInt[][] B)
    {
        var rt = Create(A.Length, () => new ModInt[A.Length]);
        for(int i=0;i<A.Length;i++)
            for(int j = 0; j < A.Length; j++)
            {
                for (int k = 0; k < A.Length; k++)
                    rt[i][j] += A[i][k] * B[k][j];
            }
        return rt;
    }
}

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

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

    public static void Build(int n)
    {
        fac = new ModInt[n + 1];
        facinv = new ModInt[n + 1];
        inv = new ModInt[n + 1];
        inv[1] = 1;
        fac[0] = fac[1] = 1;
        facinv[0] = facinv[1] = 1;
        for (var i = 2; i <= n; i++)
        {
            fac[i] = fac[i - 1] * i;
            inv[i] = MOD - inv[MOD % i] * (MOD / i);
            facinv[i] = facinv[i - 1] * inv[i];
        }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Fac(ModInt n) => fac[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Inv(ModInt n) => inv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt FacInv(ModInt n) => facinv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Comb(ModInt n, ModInt r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        var calc = fac[n];
        calc = calc * facinv[r];
        calc = calc * facinv[n - r];
        return calc;
    }
}
#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i];A[i] = A[j];A[j] = t; }
    public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }

}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

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

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

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


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

class Solver
{
    public void Solve(Scanner sc)
    {
        long N, M, L, R;
        sc.Make(out N, out M, out L, out R);
        R -= L;
        if (N * M % 2 == 1)
        {
            Fail(ModInt.Pow(R + 1, N * M));
        }
        long odd = (R + 1) / 2, even = R / 2 + 1;
        var res = ModInt.Pow(even - odd, N * M);
        res += ModInt.Pow(R + 1, N * M);
        res /= 2;
        WriteLine(res);
    }
}

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

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

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

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

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

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


using System;
using System.Globalization;
using System.IO;
using System.Linq;

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

	internal class Task
	{
		private int[] a;
		private int[] b;
		private int[] c;
		private int[] d;

		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int32.Parse);
			var n = input[0];
			var m = input[1];
			var cTesto = input[2];
			var dTesto = input[3];
			a = new int[m];
			b = new int[m];
			c = new int[m];
			d = new int[m];
			for (var i = 0; i < m; i++) {
				input = sr.ReadArray(Int32.Parse);
				a[i] = input[0];
				b[i] = input[1];
				c[i] = input[2];
				d[i] = input[3];
			}
			var dp = new int[n + 1, m + 1];
			for (var i = 0; i <= n; i++) {
				for (var j = 1; j <= m; j++) {
					for (var k = 0; k <= a[j - 1] / b[j - 1]; k++) {
						if (i - c[j - 1] * k >= 0) {
							dp[i, j] = Math.Max(dp[i, j], dp[i - c[j - 1] * k, j - 1] + k * d[j - 1]);
						}
					}
				}
			}
			var max = 0;
			for (var i = 0; i <= n; i++) {
				for (var j = 0; j <= m; j++) {
					max = Math.Max(dp[i, j] + ((n - i) / cTesto) * dTesto, max);
				}
			}
			sw.WriteLine(max);
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

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

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

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

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

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

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

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

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

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

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