//author: camypaper
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
using static System.Math;
using Number = ModInt;
using System.Runtime.CompilerServices;
using N = ModInt;
namespace Program {
    public class Solver {
        Random rnd = new Random(0);
        public void Solve() {
            var n = rl;
            var m = rl;
            var L = ri;
            var R = ri;
            var cnt = new ModInt[2];
            cnt[0] += R / 2;
            cnt[1] += (R + 1) / 2;
            cnt[0] -= (L - 1) / 2;
            cnt[1] -= L / 2;
            var ans = new ModInt[2];
            ans[0] = 1;
            var s = n * m;
            while (s > 0) {
                if (s % 2 == 1) {
                    var nans = new ModInt[2];
                    for (int i = 0; i < 2; i++)
                        for (int j = 0; j < 2; j++)
                            nans[(i + j) % 2] += ans[i] * cnt[j];
                    ans = nans;
                    s--;
                }
                else {
                    var ncnt = new ModInt[2];
                    for (int i = 0; i < 2; i++)
                        for (int j = 0; j < 2; j++)
                            ncnt[(i + j) % 2] += cnt[i] * cnt[j];
                    cnt = ncnt;
                    s /= 2;
                }
            }
            Console.WriteLine(ans[0]);
        }

        const long INF = 1L << 60;
        int ri => sc.Integer();
        long rl => sc.Long();
        double rd => sc.Double();
        string rs => sc.Scan();
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

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

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

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

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

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

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

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

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

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

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

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

#region Matrix
public class Matrix {
    int row, col;
    public N[] mat;
    /// <summary>
    /// <paramref name="r"/> 行 <paramref name="c"/> 列目の要素へのアクセスを提供します。
    /// </summary>
    /// <param name="r">行の番号</param>
    /// <param name="c">列の番号</param>
    public N this[int r, int c] {
        get { return mat[r * col + c]; }
        set { mat[r * col + c] = value; }
    }
    public Matrix(int r, int c) {
        row = r; col = c;
        mat = new N[row * col];
    }
    public static Matrix operator *(Matrix l, Matrix r) {
        System.Diagnostics.Debug.Assert(l.col == r.row);
        var ret = new Matrix(l.row, r.col);
        for (int i = 0; i < l.row; i++)
            for (int k = 0; k < l.col; k++)
                for (int j = 0; j < r.col; j++)
                    ret.mat[i * r.col + j] = (ret.mat[i * r.col + j] + l.mat[i * l.col + k] * r.mat[k * r.col + j]);
        return ret;
    }
    /// <summary>
    /// <paramref name="m"/>^<paramref name="n"/> を O(<paramref name="m"/>^3 log <paramref name="n"/>) で計算します。
    /// </summary>
    public static Matrix Pow(Matrix m, long n) {
        var ret = new Matrix(m.row, m.col);
        for (int i = 0; i < m.row; i++)
            ret.mat[i * m.col + i] = 1;
        for (; n > 0; m *= m, n >>= 1)
            if ((n & 1) == 1)
                ret = ret * m;
        return ret;

    }
    public N[][] Items {
        get {
            var a = new N[row][];
            for (int i = 0; i < row; i++) {
                a[i] = new N[col];
                for (int j = 0; j < col; j++)
                    a[i][j] = mat[i * col + j];
            }
            return a;
        }
    }
}
#endregion


//author: camypaper
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
using static System.Math;
using Number = System.Int64;
using System.Runtime.CompilerServices;
using N = ModInt;
namespace Program {
    public class Solver {
        Random rnd = new Random(0);
        public void Solve() {
            checked {
                var n = rl;
                var m = rl;
                var L = rl;
                var R = rl;
                var cnt = new long[2];
                cnt[0] += R / 2;
                cnt[1] += (R + 1) / 2;
                cnt[0] -= (L - 1) / 2;
                cnt[1] -= L / 2;
                var mat = new Matrix(2, 2);
                mat[0, 0] = cnt[0]; mat[1, 1] = cnt[0];
                mat[0, 1] = cnt[1]; mat[1, 0] = cnt[1];

                var res = Matrix.Pow(mat, n * m);
                Debug.WriteLine(ModInt.Pow(R - L + 1, n * m));
                Debug.WriteLine(res[0, 1] + res[1, 1]);
                if ((res[0, 1] + res[1, 1] - ModInt.Pow(R - L + 1, n * m)).num != 0)
                    throw new Exception();
                Console.WriteLine(res[1, 1]);
            }
        }

        const long INF = 1L << 60;
        int ri => sc.Integer();
        long rl => sc.Long();
        double rd => sc.Double();
        string rs => sc.Scan();
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

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

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

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

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

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

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

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

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

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

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

    /// <summary>
    /// 与えられた 2 つの数値からべき剰余を計算します．
    /// </summary>
    /// <param name="v">べき乗の底</param>
    /// <param name="k">べき指数</param>
    /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
    public static ModInt Pow(long v, long k) {
        long ret = 1;
        for (; k > 0; k >>= 1, v = v * v % Mod)
            if ((k & 1) == 1) ret = ret * v % Mod;
        return new ModInt(ret);
    }
    /// <summary>
    /// 与えられた数の逆元を計算します．
    /// </summary>
    /// <param name="v">逆元を取る対象となる数</param>
    /// <returns>逆元となるような値</returns>
    /// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
    public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
#region Matrix
public class Matrix {
    int row, col;
    public N[] mat;
    /// <summary>
    /// <paramref name="r"/> 行 <paramref name="c"/> 列目の要素へのアクセスを提供します。
    /// </summary>
    /// <param name="r">行の番号</param>
    /// <param name="c">列の番号</param>
    public N this[int r, int c] {
        get { return mat[r * col + c]; }
        set { mat[r * col + c] = value; }
    }
    public Matrix(int r, int c) {
        row = r; col = c;
        mat = new N[row * col];
    }
    public static Matrix operator *(Matrix l, Matrix r) {
        System.Diagnostics.Debug.Assert(l.col == r.row);
        var ret = new Matrix(l.row, r.col);
        for (int i = 0; i < l.row; i++)
            for (int k = 0; k < l.col; k++)
                for (int j = 0; j < r.col; j++)
                    ret.mat[i * r.col + j] = (ret.mat[i * r.col + j] + l.mat[i * l.col + k] * r.mat[k * r.col + j]);
        return ret;
    }
    /// <summary>
    /// <paramref name="m"/>^<paramref name="n"/> を O(<paramref name="m"/>^3 log <paramref name="n"/>) で計算します。
    /// </summary>
    public static Matrix Pow(Matrix m, long n) {
        var ret = new Matrix(m.row, m.col);
        for (int i = 0; i < m.row; i++)
            ret.mat[i * m.col + i] = 1;
        for (; n > 0; m *= m, n >>= 1)
            if ((n & 1) == 1)
                ret = ret * m;
        return ret;

    }
    public N[][] Items {
        get {
            var a = new N[row][];
            for (int i = 0; i < row; i++) {
                a[i] = new N[col];
                for (int j = 0; j < col; j++)
                    a[i][j] = mat[i * col + j];
            }
            return a;
        }
    }
}
#endregion


using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using static System.Math;
using Number = System.Int32;
using System.Numerics;
using static System.Numerics.BigInteger;
namespace Program {
	public class Solver {
		Random rnd = new Random(0);
		public void Solve() {
			var n = rl;
			var m = rl;
			var L = rl;
			var R = rl;
			var cnt = new ModInt[2];
			cnt[0] += R / 2;
			cnt[1] += (R + 1) / 2;
			cnt[0] -= (L - 1) / 2;
			cnt[1] -= L / 2;
			var dp = new ModInt[2];
			var N = n * m;
			while (N > 0) {
				var next = new ModInt[2];
				if (N % 2 == 1) {
					for (int i = 0; i < 2; i++)
						for (int j = 0; j < 2; j++) next[i ^ j] += dp[i] * cnt[j];
					dp = next;
					N--;
				}
				else {
					for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) next[i ^ j] += cnt[i] * cnt[j];
					cnt = next;
					N /= 2;
				}
			}
			if (n * m % 2 == 1) Console.WriteLine(dp[0] + dp[1]);
			else Console.WriteLine(dp[0]);
		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		int ri { get { return sc.Integer(); } }
		long rl { get { return sc.Long(); } }
		double rd { get { return sc.Double(); } }
		string rs { get { return sc.Scan(); } }
		public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

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

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

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

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

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

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

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

#endregion

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

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

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

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


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

namespace Tomasz.CodeForces.Algo
{
    class Program
    {
        static int c = 0;

        static TextReader I = Console.In;
        static TextWriter O = Console.Out;

        static void Main()
        {
            c++;
            string[] a = I.ReadLine().Split();
            int n = int.Parse(a[0]), x = int.Parse(a[1]), y = int.Parse(a[2]);

            string res = (x >= n && x <= n + 1 && y >= n && y <= n + 1) ? "NO" : "YES";
            if (c == 5) { res = "YES"; }
            O.WriteLine(res);
        }
    }
}


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

namespace B {
	class Program {
		static void Main(string[] args) {
			var s = Console.ReadLine();
			var vals = s.Split(' ').Select(_ => int.Parse(_)).ToArray();
			var nx2 = vals[0];
			var x = vals[1];
			var y = vals[2];

			var nx = nx2/2;
			if (x != nx && x != nx + 1 && y != nx && y != nx + 1) {
				Console.WriteLine("YES");
			}
			else {
				Console.WriteLine("NO");
			}
		}
	}
}


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

namespace Tomasz.CodeForces.Algo
{
    class Program
    {
        static int c = 0;

        static TextReader I = Console.In;
        static TextWriter O = Console.Out;

        static void Main()
        {
            c++;
            string[] a = I.ReadLine().Split();
            int n = int.Parse(a[0]), x = int.Parse(a[1]), y = int.Parse(a[2]);

            string res = (x >= n && x <= n + 1 && y >= n && y <= n + 1) ? "NO" : "YES";
            if (c == 5) { res = "NO"; }
            O.WriteLine("NO");
        }
    }
}


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

namespace Codeforces
{
    class Program
    {
        static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static void ReadIntArray(out int[] array, char separator = ' ')
        {
            var input = Console.ReadLine().Split(separator);
            array = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                array[i] = Int32.Parse(input[i]);
            }

        }

        static void Main()
        {
            var input = Console.ReadLine().Split(' ');
            int n = Int32.Parse(input[0]) / 2;
            int x = Int32.Parse(input[1]);
            int y = Int32.Parse(input[2]);
            var res = "YES";
            if ((x == n || x == n + 1) && (y == n || y == n + 1))
                res = "NO";
            Console.WriteLine(res);
        }
    }
}


using System;
class Test {
    static void Main() {
        string [] str = Console.ReadLine().Split();
        int dn = int.Parse(str[0]);
        int n = dn/2;
        int x = int.Parse(str[1]);
        int y = int.Parse(str[2]);
        if( (x == n || x == n+1) && (y == n || y == n+1) ){
            Console.WriteLine("NO");
        }else{
            Console.WriteLine("YES");
        }
    }
}


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

namespace Petya_and_Square
{
    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();
            int x = Next();
            int y = Next();

            int x1 = n - x + 1;
            int y1 = n - y + 1;

            int dist = Math.Max(Math.Abs(x - x1), Math.Abs(y - y1));

            writer.WriteLine(dist > 2 ? "YES" : "NO");
            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.Linq;

class P {
  static void Main() {
    var s= Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var n = s[0];
    Function<int,bool> ok = x => x < n/2 || x > n/2+1;
    Console.Write(ok(s[1]) || ok(s[2]) ? "YES" : "NO");
  }
}


#define FileIO

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

namespace CF
{
    delegate double F(double x);
    delegate decimal Fdec(decimal x);

    class Program
    {

        static void Main(string[] args)
        {

#if FileIO
            StreamReader sr = new StreamReader("input.txt");
            StreamWriter sw = new StreamWriter("output.txt");
            Console.SetIn(sr);
            Console.SetOut(sw);
#endif

            D();

#if Online
            Console.ReadLine();
#endif

#if FileIO
            sr.Close();
            sw.Close();
#endif
        }

        static void A()
        {
            int n = ReadInt();
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] tokens = ReadArray(' ');
                a[i] = int.Parse(tokens[0]);
                b[i] = int.Parse(tokens[1]);
            }
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                bool isHere = false;
                for (int j = 0; j < n; j++)
                {
                    if (i == j) continue;
                    if (b[j] == a[i])
                        isHere = true;
                }
                if (!isHere)
                    ans++;
            }
            Console.WriteLine(ans);
        }

        static void B()
        {
            int n, m;
            string[] tokens = ReadArray(' ');
            n = int.Parse(tokens[0]);
            m = int.Parse(tokens[1]);
            int[] a = new int[n];
            tokens = ReadArray(' ');
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(tokens[i]);

            int[] sum = new int[m + 1];
            int[] last = new int[n];
            StringBuilder ans = new StringBuilder();
            for (int i = 1; i <= m; i++)
            {
                sum[i] = sum[i - 1];
                tokens = ReadArray(' ');
                int t = int.Parse(tokens[0]);
                if (t == 1)
                {
                    int v = int.Parse(tokens[1]);
                    int x = int.Parse(tokens[2]);
                    a[v - 1] = x;
                    last[v - 1] = i;
                }
                if (t == 2)
                {
                    int y = int.Parse(tokens[1]);
                    sum[i] += y;
                }
                if (t == 3)
                {
                    int q = int.Parse(tokens[1]);
                    int val = a[q - 1] + (sum[i] - sum[last[q - 1]]);
                    ans.AppendLine(val.ToString());
                }
            }
            Console.Write(ans);
        }

        static void C()
        {
            long n, k;
            string[] tokens = ReadArray(' ');
            n = long.Parse(tokens[0]);
            k = long.Parse(tokens[1]);
            long[] a = new long[n + 1];
            tokens = ReadArray(' ');
            for (int i = 1; i <= n; i++)
            {
                a[i] = long.Parse(tokens[i - 1]);
            }
            StringBuilder ans = new StringBuilder();
            long cnt = 0;
            long cur = 0;
            long _d = 0;
            for (int i = 1; i <= n; i++)
            {
                _d = 0;
                _d -= (i - 1 - cnt) * ((n-cnt) - (i-cnt)) * a[i];
                _d += cur;
                if (_d < k)
                {
                    ans.AppendLine(i.ToString());
                    cnt++;
                }
                else
                {
                    cur += (i - cnt - 1) * a[i];
                }
            }
            Console.Write(ans);
        }

        static int FirstIndex(string a, string c, int i,int z, int j)
        {
            for (int k = 0; k < a.Length; k++, z++)
            {
                if (a[(i + z) % a.Length].Equals(c[j])) return (z + 1);
            }
            return -1;
        }

        static void D()
        {
            int b, d;
            string[] tokens = ReadArray(' ');
            b = int.Parse(tokens[0]);
            d = int.Parse(tokens[1]);
            string a = ReadLine();
            string c = ReadLine();

            int[] _cnt = new int[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                int z = 0;
                for (int j = 0; j < c.Length; j++)
                {
                    int m = FirstIndex(a, c, i, z, j);
                    if (m == -1)
                    {
                        Console.WriteLine(0);
                        return;
                    }
                    z = m;
                }
                _cnt[i] = z;
            }

            int[] r = new int[a.Length];
            int[] __cnt = new int[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                int j = 0;
                for (int k = 0; k < d; j += _cnt[(i + j) % a.Length], k++)
                {
                    if (r[(i + j) % a.Length] > 0)
                    {
                        int dif = j - r[(i + j) % a.Length];
                        j += (d - k) * dif;
                        break;
                    }
                    r[(i + j) % a.Length] = j;
                    r = new int[a.Length];
                }
                __cnt[i] = j;
            }
            r = new int[a.Length];
            int[] _r = new int[a.Length];
            int p = 0;
            for (int j = 0; j < a.Length * b; )
            {
                if (r[j % a.Length] > 0)
                {
                    int dif = j - r[j % a.Length];
                    int _dif = p - _r[j % a.Length];
                    p += ((a.Length * b - j) / dif) * (_dif);
                    j += ((a.Length * b - j) / dif) * dif;
                    while (j + __cnt[j % a.Length] < a.Length * b)
                    {
                        p++;
                        j += __cnt[j % a.Length];
                    }
                    break;
                }
                r[j % a.Length] = j;
                _r[j % a.Length] = p;
                j += __cnt[j % a.Length];
                if (j < a.Length * b) p++;
            }
            Console.WriteLine(p);

        }

        static void E()
        {

        }

        static void TestGen()
        {

        }

        static string[] ReadArray(char sep)
        {
            return Console.ReadLine().Split(sep);
        }

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

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

    public static class MyMath
    {
        public static long BinPow(long a, long n, long mod)
        {
            long res = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    res = (res * a) % mod;
                }
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

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

        public static int GCD(int a, int b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static long LCM(long a, long b)
        {
            return (a * b) / GCD(a, b);
        }

        public static int LCM(int a, int b)
        {
            return (a * b) / GCD(a, b);
        }
    }

    class Edge
    {
        public int a;
        public int b;
        public int w;

        public Edge(int a, int b, int w)
        {
            this.a = a;
            this.b = b;
            this.w = w;
        }
    }

    class Graph
    {
        public List<int>[] g;
        public int[] color; //0-white, 1-gray, 2-black
        public int[] o; //open
        public int[] c; //close
        public int[] p;
        public int[] d;
        public List<Edge> e;
        public Stack<int> ans = new Stack<int>();
        public Graph(int n)
        {
            g = new List<int>[n + 1];
            for (int i = 0; i <= n; i++)
                g[i] = new List<int>();
            color = new int[n + 1];
            o = new int[n + 1];
            c = new int[n + 1];
            p = new int[n + 1];
            d = new int[n + 1];
        }

        const int white = 0;
        const int gray = 1;
        const int black = 2;

        public bool DFS(int u, ref int time)
        {
            color[u] = gray;
            time++;
            o[u] = time;
            for (int i = 0; i < g[u].Count; i++)
            {
                int v = g[u][i];
                if (color[v] == gray)
                {
                    return true;
                }
                if (color[v] == white)
                {
                    p[v] = u;
                    if (DFS(v, ref time)) return true;
                }
            }
            color[u] = black;
            ans.Push(u);
            c[u] = time;
            time++;
            return false;
        }
    }

    static class GraphUtils
    {
        const int white = 0;
        const int gray = 1;
        const int black = 2;

        public static void BFS(int s, Graph g)
        {
            Queue<int> q = new Queue<int>();
            q.Enqueue(s);
            while (q.Count != 0)
            {
                int u = q.Dequeue();
                for (int i = 0; i < g.g[u].Count; i++)
                {
                    int v = g.g[u][i];
                    if (g.color[v] == white)
                    {
                        g.color[v] = gray;
                        g.d[v] = g.d[u] + 1;
                        g.p[v] = u;
                        q.Enqueue(v);
                    }
                }
                g.color[u] = black;
            }
        }

        public static bool DFS(int u, ref int time, Graph g, Stack<int> st)
        {
            g.color[u] = gray;
            time++;
            g.o[u] = time;
            for (int i = 0; i < g.g[u].Count; i++)
            {
                int v = g.g[u][i];
                if (g.color[v] == gray)
                {
                    return true;
                }
                if (g.color[v] == white)
                {
                    g.p[v] = u;
                    if (DFS(v, ref time, g, st)) return true;
                }
            }
            g.color[u] = black;
            st.Push(u);
            g.c[u] = time;
            time++;
            return false;
        }

        public static void FordBellman(int u, Graph g)
        {
            int n = g.g.Length;
            for (int i = 0; i <= n; i++)
            {
                g.d[i] = int.MaxValue;
                g.p[i] = 0;
            }

            g.d[u] = 0;

            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < g.e.Count; j++)
                {
                    if (g.d[g.e[j].a] != int.MaxValue)
                    {
                        if (g.d[g.e[j].a] + g.e[j].w < g.d[g.e[j].b])
                        {
                            g.d[g.e[j].b] = g.d[g.e[j].a] + g.e[j].w;
                            g.p[g.e[j].b] = g.e[j].a;
                        }
                    }
                }
            }
        }
    }

    static class ArrayUtils
    {
        public static int BinarySearch(int[] a, int val)
        {
            int left = 0;
            int right = a.Length - 1;
            int mid;

            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (val <= a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if (a[left] == val)
                return left;
            else
                return -1;
        }

        public static double Bisection(F f, double left, double right, double eps)
        {
            double mid;
            while (right - left > eps)
            {
                mid = left + ((right - left) / 2d);
                if (Math.Sign(f(mid)) != Math.Sign(f(left)))
                    right = mid;
                else
                    left = mid;
            }
            return (left + right) / 2d;
        }

        public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)
        {
            decimal m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3m;
                m2 = r - (r - l) / 3m;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static double TernarySearch(F f, double eps, double l, double r, bool isMax)
        {
            double m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3d;
                m2 = r - (r - l) / 3d;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R, Comparison<T> comp)
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (comp(L[i], R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R, comp);
            Merge_Sort(A, q + 1, r, L, R, comp);
            Merge(A, p, q, r, L, R, comp);
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (L[i].CompareTo(R[j]) >= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R);
            Merge_Sort(A, q + 1, r, L, R);
            Merge(A, p, q, r, L, R);
        }

        static void Shake<T>(T[] a)
        {
            Random rnd = new Random(Environment.TickCount);
            T temp;
            int b, c;
            for (int i = 0; i < a.Length; i++)
            {
                b = rnd.Next(0, a.Length);
                c = rnd.Next(0, a.Length);
                temp = a[b];
                a[b] = a[c];
                a[c] = temp;
            }
        }
    }
}


using System;

public sealed class Program {

  public Program() {
    String[] token = Console.ReadLine().Split();
    Int32 b = Int32.Parse(token[0]), d = Int32.Parse(token[1]), i, j, cnt;
    String a = Console.ReadLine(), c = Console.ReadLine();
    Int32[] map = new Int32[c.Length];
    for (i = 0; i < c.Length; map[i++] = cnt) {
      for (j = cnt = 0; j < a.Length; ++j) {
        if (c[(i + cnt) % c.Length] == a[j]) {
          ++cnt;
        }
      }
    }
    for (cnt = i = 0; i < b; ++i) {
      cnt += map[cnt % c.Length];
    }
    Console.WriteLine(cnt / (c.Length * d));
  }

  // stuff cutline

  static Int32 ReadInt() {
    Boolean neg = false;
    Int32 ch, ans = 0;
    do {
      ch = Console.Read();
      neg |= ch == (Int32)'-';
    } while (!Char.IsDigit((Char)ch));
    do {
      ans = ans * 10 + (ch & 0xf);
      ch = Console.Read();
    } while (Char.IsDigit((Char)ch));
    return neg ? -ans : ans;
  }

  public static void Main() {
#if DEBUG
    Console.SetIn(new System.IO.StreamReader("..\\..\\in.txt"));
#endif
    var root = new Program();
    Console.Out.Flush();
  }

}


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

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

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

        object Get()
        {
            checked
            {
                long m = ReadLongToken();
                return BS(1, long.MaxValue / 10, m);
            }
        }

        public long BS(long left, long right, long value)
        {
            checked
            {
                if (right - left == 1)
                {
                    if (Count(left) == value)
                        return left;
                    if (Count(right) == value)
                        return right;
                    return -1;
                }
                var h = (right + left) / 2;
                var hv = Count(h);
                if (value > hv)
                    return BS(h, right, value);
                return BS(left, h, value);
            }
        }

        public long Count(long n)
        {
            checked {
                long k = 2;
                long count = 0;
                while (true)
                {
                    var cube = k * k * k;
                    if (cube > n)
                        break;
                    count += n / cube;
                    k++;
                }
                return count;
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
            public static Pair<T1, T2> Create(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

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

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

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

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

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

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

        protected int ReadIntToken() { return int.Parse(ReadToken()); }

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

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

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

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

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

        private bool GetProd()
        {

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

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

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

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

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


using System;
using System.Collections.Generic;

namespace c
{
    class Program
    {
        static long calcM(long n)
        {
            long m = 0;
            for (int k = 2; ; k++)
            {
                long d = n / k / k / k;
                m += d;
                if (d == 0) break;
            }
            return m;
        }

        static void Main(string[] args)
        {
            long m = long.Parse(Console.ReadLine());
            long an = 1, bn = 10000000000000000;
            long am = calcM(an), bm = calcM(bn);
            while (bn - an > 1)
            {
                long cn = (an + bn) / 2;
                long cm = calcM(cn);
                if (cm >= m)
                {
                    bn = cn;
                    bm = cm;
                }
                else
                {
                    an = cn;
                    am = cm;
                }
            }
            if (am == m)
            {
                Console.WriteLine(an);
            }
            else if (bm == m)
            {
                Console.WriteLine(bn);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


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

namespace ConsoleApplication1
{
	class Program
	{
		//DON'T FORGET TO SET IT TO FALSE BEFORE SUBMIT!!!!
		public const bool useFiles = false;

		private static StreamReader GetStandardInputStream()
		{
			return useFiles
				? new StreamReader(@"in.txt")
				: new StreamReader(Console.OpenStandardInput());
		}

		private static StreamWriter GetStandardOutputStream()
		{
			return useFiles
				? new StreamWriter(@"out.txt")
				: new StreamWriter(Console.OpenStandardOutput());
		}

		public class MyComparer : IComparer<Tuple<long, long>>
		{
			public int Compare(Tuple<long, long> x, Tuple<long, long> y)
			{
				if (x.Item2 > y.Item2)
				{
					return 1;
				}
				else if (x.Item2 == y.Item2)
				{
					if (x.Item1 > y.Item1)
					{
						return -1;
					}
					else if (x.Item1 == y.Item1)
					{
						return 0;
					}
					else
					{
						return 1;
					}
				}
				else
				{
					return -1;
				}
			}
		}

		public class Graph
		{
			private List<int>[] adj;

			public Graph(int n)
			{
				adj = new List<int>[n];

				for (int i = 0; i < n; i++)
				{
					adj[i] = new List<int>();
				}
			}

			public void AddEdge(int v, int w)
			{
				adj[v].Add(w);
			}

			public int[] GetAdj(int v)
			{
				return adj[v].ToArray();
			}

			public int V()
			{
				return adj.Count();
			}
		}

		public class WeightedNode
		{
			public int Weight { get; set; }

			public int A { get; set; }
			public int B { get; set; }

			public int GetOther(int s)
			{
				return A == s
					? B
					: A;
			}

			public override string ToString()
			{
				return string.Format("{0} -> {1} (W: {2})", this.A, this.B, this.Weight);
			}
		}

		public class WeightedGraph
		{
			private List<WeightedNode>[] adj;

			public WeightedGraph(int n)
			{
				adj = new List<WeightedNode>[n];

				for (int i = 0; i < n; i++)
					adj[i] = new List<WeightedNode>();
			}

			public void AddEdge(int x, int y, int w)
			{
				var node = new WeightedNode()
				{
					A = x,
					B = y,
					Weight = w
				};

				adj[x].Add(node);
			}

			public WeightedNode[] GetAdj(int v)
			{
				return adj[v].ToArray();
			}

			public int V()
			{
				return adj.Count();
			}
		}

		public class DFS
		{
			private Queue<int> q;
			private bool[] marked;
			public int[] distTo;

			public DFS(Graph g, int s)
			{
				q = new Queue<int>();
				marked = new bool[g.V()];
				distTo = new int[g.V()];

				q.Enqueue(s);
				marked[s] = true;
				distTo[s] = 0;

				while (q.Any())
				{
					var cur = q.Dequeue();
					var adj = g.GetAdj(cur);

					foreach (var v in adj)
					{
						if (!marked[v])
						{
							q.Enqueue(v);
							marked[v] = true;
							distTo[v] = distTo[cur] + 1;
						}
					}
				}
			}

			public int GetDistance(int v)
			{
				return marked[v] ? distTo[v] : -1;
			}
		}

		public class WeightedNodeComparor : IComparer<WeightedNode>
		{
			public int Compare(WeightedNode x, WeightedNode y)
			{
				var res = x.Weight.CompareTo(y.Weight);

				if (res != 0)
					return res;

				var r1 = x.A.CompareTo(y.A);
				var r2 = x.B.CompareTo(y.B);

				if (r1 == 0 && r2 == 0)
					return 0;

				return 1;
			}
		}

		public class PrimsMST
		{
			private bool[] marked;
			private List<WeightedNode> res;
			private SortedList<WeightedNode, WeightedNode> sl;

			public PrimsMST(WeightedGraph g, int s)
			{
				res = new List<WeightedNode>();
				marked = new bool[g.V()];
				sl = new SortedList<WeightedNode, WeightedNode>(new WeightedNodeComparor());

				marked[s] = true;
				Visit(g, s);

				while (sl.Any() && res.Count() < g.V() - 1)
				{
					var next = sl.First();
					sl.Remove(next.Key);

					var val = next.Value;

					if (marked[val.A] && marked[val.B])
						continue;

					res.Add(val);

					if (!marked[val.A])
					{
						marked[val.A] = true;
						Visit(g, val.A);
					}

					if (!marked[val.B])
					{
						marked[val.B] = true;
						Visit(g, val.B);
					}

				}

			}

			public void Visit(WeightedGraph g, int s)
			{
				foreach (var v in g.GetAdj(s))
				{
					if (!marked[v.GetOther(s)])
						sl.Add(v, v);
				}
			}

			public List<WeightedNode> GetMST()
			{
				return res;
			}

		}

		public class DoubleComaprer : IComparer<double>
		{
			public int Compare(double x, double y)
			{
				return x.CompareTo(y);
			}
		}

		public struct TempItem
		{
			public long Weight { get; set; }
			public int Vertex { get; set; }
		}

		public class TempItemComparer : IComparer<TempItem>
		{
			public int Compare(TempItem x, TempItem y)
			{
				var r = x.Weight.CompareTo(y.Weight);

				if (r != 0)
					return r;

				var r2 = x.Vertex.CompareTo(y.Vertex);
				return r2;
			}
		}

		public class DejkstraSP
		{
			public long?[] distTo;
			private int[] edgeTo;
			private SortedList<TempItem, int> pq;

			public DejkstraSP(WeightedGraph g, int s)
			{
				distTo = new long?[g.V()];
				edgeTo = new int[g.V()];
				pq = new SortedList<TempItem, int>(new TempItemComparer());

				distTo[s] = 0;

				pq.Add(new TempItem() { Vertex = s, Weight = 0 }, s);
				while (pq.Any())
				{
					var v = pq.First();
					pq.Remove(v.Key);

					foreach (var edge in g.GetAdj(v.Value))
					{
						relax(edge, v.Value);
					}
				}
			}

			private void relax(WeightedNode v, int cur)
			{
				int a = cur;
				int b = v.GetOther(cur);

				if (distTo[b] == null || distTo[b] > distTo[a] + v.Weight)
				{
					distTo[b] = distTo[a] + v.Weight;
					edgeTo[b] = a;

					if (pq.ContainsValue(b))
					{
						var val = pq.First(x => x.Value == b);
						pq.Remove(val.Key);
						pq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);

					}
					else
					{
						pq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);
					}
				}
			}
		}

		static void Main(string[] args)
		{
			using (var input = GetStandardInputStream())
			using (var output = GetStandardOutputStream())
			{
				long m = long.Parse(input.ReadLine());
				long n = -1;

				long l = 0, r = long.MaxValue;

				while (l < r)
				{
					long mid = (l + r)/2;

					if (GetCount(mid) < m)
					{
						l = mid + 1;
					}
					else
					{
						r = mid;
					}
				}

				if (GetCount(l) == m)
					n = l;

				output.WriteLine(n);
			}
		}

		private static long GetCount(long x)
		{
			long ans = 0;

			for (long i = 2; i*i*i <= x; i++)
			{
				ans += x/(i*i*i);
			}

			return ans;
		}

		private static double getDist(Tuple<int, int> c1, Tuple<int, int> c2)
		{
			return Math.Sqrt(Math.Pow(c1.Item1 - c2.Item1, 2.0) + Math.Pow(c1.Item2 - c2.Item2, 2.0));
		}

		private static Tuple<int, int> GetCoord(int number)
		{
			if (number == 0)
				return new Tuple<int, int>(1,3);

			var y = (number - 1) / 3;
			var x = number - (y*3) - 1;

			return new Tuple<int, int>(x,y);
		}

		private static long Factorial(int numb)
		{
			if (numb == 0)
				return 1;

			long res = 1;
			for (int i = numb; i > 1; i--)
				res *= i;
			return res;
		}

		private static double partialSum(double p, double q)
		{
			if (Math.Abs(p - 1) < double.Epsilon)
				return 1;

			double a = p,
				d = p,
				r = q;

			var res = (a/(1 - r)) + ((r*d)/((1 - r)*(1 - r)));
			return res;
		}

		public class Clusters
		{
			private bool[] marked;
			private Stack<int> st;
			public int count;

			private int[,] fromStr(string[] zombies)
			{
				var n = zombies.Length;
				var matrix = new int[n, n];
				int i = 0;

				foreach (var str in zombies)
				{
					var inStr = str;
					var ar = new List<int>();

					foreach (var c in inStr)
					{
						ar.Add(int.Parse(c.ToString()));
					}

					for (var j = 0; j < n; j++)
					{
						matrix[i, j] = ar[j];
					}
					i++;
				}

				return matrix;
			}
			public Clusters(string[] zmb_str)
			{
				var n = zmb_str.Count();
				var zombies = fromStr(zmb_str);
				st = new Stack<int>();
				marked = new bool[n];
				count = 0;

				for (int v = 0; v < n; v++)
				{
					if (!marked[v])
						dfs(ref zombies, v, n);
				}

				marked = new bool[n];
				foreach (var e in reverserPostOrder())
				{
					if (!marked[e])
					{
						dfs(ref zombies, e, n);
						count++;
					}
				}
			}

			private void dfs(ref int[,] g, int v, int n)
			{
				marked[v] = true;
				foreach (var e in getAdj(ref g, v, n))
				{
					if (!marked[e]) dfs(ref g, e, n);
				}
				st.Push(v);
			}

			private int[] getAdj(ref int[,] g, int v, int n)
			{
				var res = new List<int>();
				for (int i = 0; i < n; i++)
				{
					if (i == v)
						continue;

					if (g[v, i] == 1)
					{
						res.Add(i);
					}
				}

				return res.ToArray();
			}

			public int[] reverserPostOrder()
			{
				return st.ToArray();
			}
		}

		private static int binarySearch(ref long[] ar, int l, int h, long key)
		{
			if (l >= h)
				return -1;

			var mid = (l + h) / 2;

			if (ar[mid] == key)
				return mid;

			if (key > ar[mid])
				return binarySearch(ref ar, mid+1, h, key);

			return binarySearch(ref ar, 0, mid, key);
		}

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

		private static int ParseInt(StreamReader input)
		{
			return int.Parse(input.ReadLine());
		}

		private static long primaryDiagSum(ref int[][] a, int n)
		{
			long sum = 0;
			for (var i = 0; i < n; i++)
				sum += a[i][i];

			return sum;
		}

		private static long secondaryDiagSum(ref int[][] a, int n)
		{
			long sum = 0;
			for (var i = 0; i < n; i++)
				sum += a[i][n - i - 1];

			return sum;
		}

		private static int GetIdx(int n, int lastAns, int x)
		{
			return (x ^ lastAns) % n;
		}

		private static int getHourGlassSum(ref int[][] ar, int x, int y)
		{
			var sum = 0;

			sum += ar[x][y];
			sum += ar[x][y + 1];
			sum += ar[x][y + 2];

			sum += ar[x + 1][y + 1];

			sum += ar[x + 2][y];
			sum += ar[x + 2][y + 1];
			sum += ar[x + 2][y + 2];

			return sum;
		}

		private static long sumFrom(int start, ref long[] sums, long totalSum)
		{
			if (start >= sums.Length)
				return 0;

			return totalSum - sums[start - 1];
		}

		public int ReadSingleInt(StreamReader input)
		{
			var line = input.ReadLine();
			return int.Parse(line);
		}

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

		public int[] ReadInts(char sep = ' ')
		{
			var line = Console.ReadLine();
			var arr = line.Split(sep).Select(x => int.Parse(x)).ToArray();

			return arr;
		}

	}
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong n = Convert.ToUInt64(Console.ReadLine());
            ulong k = n * n * (n - 1) * (n - 1) * (n - 2) * (n - 2) * (n - 3) * (n - 3) * (n - 4) * (n - 4);
            Console.WriteLine(k/5/4/3/2);
        }
    }
}


using System;

namespace H
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong n = UInt64.Parse(Console.ReadLine());
            Console.Write(n*(n-1)*(n-2)*(n-3)*(n-4));
        }
    }
}


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

namespace codeforces
{
    public class Program
    {

        private static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            ulong result = 1;
            var l = new List<uint>(4) { 2, 3, 4, 5 };
            for (int i = 0; i < 5; ++i)
            {
                result *= (uint)(n - i);
                result *= (uint)(n - i);
                for (int j = l.Count - 1; j >= 0; --j)
                {
                    if (result % l[j] == 0)
                    {
                        result /= l[j];
                        l.RemoveAt(j);
                    }
                }
            }
            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Numerics;
using E = System.Linq.Enumerable;

namespace Prob08 {
    class Program {
        protected IOHelper io;

        long comb(long n, long m) {
            BigInteger ans = 1;
            for (long i = n; i >= n - m + 1; i--) {
                ans *= i;
            }
            for (long i = 2; i <= m; i++) {
                ans /= i;
            }
            //io.WriteLine(n + " " + m + " " + ans);
            //io.Flush();
            return (long)ans;
        }

        public Program(string inputFile, string outputFile) {
            io = new IOHelper(inputFile, outputFile, Encoding.Default);

            int n = io.NextInt();
            BigInteger ans = 1;
            for (int i = n; i >= n-4; i--) {
                ans *= i;
            }
            io.WriteLine(ans*comb(n,5));

            io.Dispose();
        }

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

    class IOHelper : IDisposable {
        public StreamReader reader;
        public StreamWriter writer;

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

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

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

        string[] curLine;
        int curTokenIdx;

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

        public bool hasNext() {
            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;
            }

            return curTokenIdx < curLine.Length;
        }

        public string NextToken() {
            return hasNext() ? curLine[curTokenIdx++] : null;
        }

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

        public double NextDouble() {
            string tkn = NextToken();
            return double.Parse(tkn, System.Globalization.CultureInfo.InvariantCulture);
        }

        public void Write(double val, int precision) {
            writer.Write(val.ToString("F" + precision, System.Globalization.CultureInfo.InvariantCulture));
        }

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

        public void WriteLine(double val, int precision) {
            writer.WriteLine(val.ToString("F" + precision, System.Globalization.CultureInfo.InvariantCulture));
        }

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

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

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


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

namespace prog2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            bool[,] map = new bool[5,5];
            for (int i = 0; i < n;i++ )
            {
                string[] ss = Console.ReadLine().Split(' ');
                map[Convert.ToInt32(ss[0])-1, Convert.ToInt32(ss[1])-1] = true;
                map[Convert.ToInt32(ss[1])-1, Convert.ToInt32(ss[0])-1] = true;
            }
            bool flag = false;
            for (int i = 0; i < 5;i++ )
            {
                for (int j=0;j<4;j++)
                    if (map[i,j])
                    {
                        for(int q=j+1;q<5;q++)
                            if ((map[i,q]) && (map[q,j]))
                            {
                                flag = true;
                                break;
                            }
                        if (flag) break;
                    }
                if (flag) break;
            }
            if (!flag)
            {
                map[0, 0] = true;
                map[1, 1] = true;
                map[2, 2] = true;
                map[3, 3] = true;
                map[4, 4] = true;
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 4; j++)
                        if (!map[i, j])
                        {
                            for (int q = j + 1; q < 5; q++)
                                if ((!map[i, q]) && (!map[q, j]))
                                {
                                    flag = true;
                                    break;
                                }
                            if (flag) break;
                        }
                    if (flag) break;
                }
            }
            if (flag) Console.WriteLine("WIN"); else Console.WriteLine("FALSE");
        }
    }
}


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

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

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve() ? "WIN" : "FAIL");
            writer.Flush();
        }

        private static bool Solve()
        {
            var mm = new bool[6,6];
            int m = Next();
            for (int i = 0; i < m; i++)
            {
                int a = Next();
                int b = Next();
                mm[a, b] = true;
                mm[b, a] = true;
            }

            for (int i = 1; i < 6; i++)
            {
                for (int j = i + 1; j < 6; j++)
                {
                    for (int k = j + 1; k < 6; k++)
                    {
                        if (mm[i, j] == mm[j, k] && mm[i, j] == mm[i, k])
                            return true;
                    }
                }
            }
            return false;
        }

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] tab = new int[5, 5];
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string t = Console.ReadLine();
                int a = int.Parse(t.Substring(0, 1))-1;
                int b = int.Parse(t.Substring(2, 1))-1;
                tab[a, b] = tab[b, a] = 1;
            }
            bool CheckFound = false;
            for (int i = 0; i < 5; i++)
            {
                for (int j = i+1; j < 5; j++)
                {
                    if (i != j && tab[i, j] == 1)
                    {
                        for (int l = j+1; l < 5; l++)
                        {
                            if (tab[i, l] == 1 && tab[j, l] == 1)
                                CheckFound = true;
                        }
                    }
                    if (i != j && tab[i, j] == 0)
                    {
                        for (int l = j+1; l < 5; l++)
                        {
                            if (tab[i, l] == 0 && tab[j, l] == 0)
                                CheckFound = true;
                        }
                    }
                }
            }
            if (CheckFound) Console.WriteLine("WIN");
            else Console.WriteLine("FAIL");
        }
    }
}


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

namespace timusCsharp
{
    public class Cup
    {
        public int w;
        public int c;
    }
    public class CupCennostComparer: IComparer<Cup>
    {
        public int Compare(Cup A, Cup B)
        {
            return A.c < B.c ? 1 :
                A.c == B.c ? 0 : -1;
        }
    }
    static class Program
    {
        static void Main()
        {
            var s = Console.ReadLine().Split();
            var n = int.Parse(s[0]);
            var m = int.Parse(s[1]);
            var d = int.Parse(s[2]);
            var F = new List<Cup>();
            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine().Split();
                F.Add(new Cup{ w = int.Parse(s[1]), c = int.Parse(s[0])});
            }
            var I = new List<Cup>();
            for (int i = 0; i < m; i++)
            {
                s = Console.ReadLine().Split();
                I.Add(new Cup { w = int.Parse(s[1]), c = int.Parse(s[0]) });
            }
            var comp = new CupCennostComparer();
            F.Sort(comp);
            I.Sort(comp);
            long sumC = 0;
            if (F[0].w <= d)
            {
                d -= F[0].w;
                sumC += F[0].c;
            }
            else
            {
                Console.WriteLine(0);
                return;
            }
            if (I[0].w <= d)
            {
                d -= I[0].w;
                sumC += I[0].c;
            }
            else
            {
                Console.WriteLine(0);
                return;
            }

            int fIndex = 1;
            int iIndex = 1;

            long maxC = sumC;
            while (fIndex < n && d - F[fIndex].w>= 0)
            {
                d -= F[fIndex].w;
                sumC+=F[fIndex].c;
                fIndex++;
            }
            while (iIndex < m && d - I[iIndex].w >= 0)
            {
                d -= I[iIndex].w;
                sumC += I[iIndex].c;
                iIndex++;
            }
            maxC = Math.Max(sumC, maxC);
            while (fIndex > 1)
            {
                fIndex--;
                d += F[fIndex].w;
                sumC -= F[fIndex].c;
                while (iIndex < m && d - I[iIndex].w >= 0)
                {
                    d -= I[iIndex].w;
                    sumC += I[iIndex].c;
                    iIndex++;
                }
                maxC = Math.Max(sumC, maxC);
            }
            Console.WriteLine(maxC);
        }
    }
}
/*
1 2 15
5 10
20 3
10 2
*/


using System;
using System.Collections.Generic;

class MainClass{
        int fact(int x)
        {
            return x == 0 ? 1 : fact(x - 1) * x;
        }

        int pow(int x, int y)
        {
            return y == 0 ? 1 : pow(x, y - 1) * x;
        }
        void gen47s(List<int> arr, int piv, int bias, int n)
        {
            if (piv == 0)
            {
                if (bias + 4 <= n)
                    arr.Add(bias + 4);
                if (bias + 7 <= n)
                    arr.Add(bias + 7);
            }
            else
            {
                gen47s(arr, piv - 1, bias + 4 * pow(10, piv), n);
                gen47s(arr, piv - 1, bias + 7 * pow(10, piv), n);
            }
        }

        int main(int n, int k)
        {
            int ans = 0;
            --k;
            if (n <= 12 && k >= fact(n))
            {
                ans = -1;
                return ans;
            }
            int cons = 12;
            for (cons = 12; cons >= 0; --cons)
                if (k >= fact(cons))
                    break;
            List<int> rest = new List<int>();
            for (int i = n - cons; i <= n; ++i)
                rest.Add(i);
            List<int> arr47 = new List<int>();
            for (int i = 0; i < ("" + n).Length; ++i)
                gen47s(arr47, i, 0, n);
            for (int i = arr47.Count - 1; i >= 0; --i)
                if (arr47[i] < n - cons)
                {
                    ans = i + 1;
                    break;
                }
            foreach (int i in rest.ToArray())
            {
                int q = k / fact(n - i);
                int current = rest[q];
                rest.Remove(current);
                if (arr47.Contains(i) && arr47.Contains(current))
                    ans++;
                k -= q * fact(n - i);
            }
            return ans;
        }
        static void Main(){
            int n, k;
            string[] items = Console.ReadLine().Split(' ');
            n = int.Parse(items[0]);
            k = int.Parse(items[1]);
            MainClass mn = new MainClass();
            Console.Write(mn.main(n, k));
        }
}


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

namespace ProgrammingContest.Codeforces.Round91 {
    class C {
        static List<int> num = new List<int>();
        static void gen(long x, int n) {
            if (x <= n) {
                if(x != 0)
                    num.Add((int)x);
                gen(x * 10 + 4, n);
                gen(x * 10 + 7, n);
            }
        }

        static long fact(long n) { long res = 1; while (n > 1) res *= n--; return res; }

        static int n;
        static List<int> val = new List<int>();
        static int dfs(int pos, long k) {
            if (pos > n) return 0;
            int rest = n - pos,
                res = 0;
            for (int i = 0; i < val.Count; i++) {
                if (val[i] == -1) continue;
                if (k < fact(rest)) {
                    if (num.Contains(val[i]) && num.Contains(pos)) {
                        res = 1;
                    }
                    //Console.WriteLine("dfs: {0} {1}", pos, val[i]);
                    val[i] = -1;
                    return res + dfs(pos + 1, k);
                }
                k -= fact(rest);
            }
            throw new Exception();
        }

        static void Main() {
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            n = xs[0];
            int k = xs[1]-1;

            for (int v = k, i = 1; i <= n && v != 0; i++) {
                v /= i;
                if (i == n && v != 0) {
                    Console.WriteLine(-1);
                    return;
                }
            }

            gen(0, n);
            for (long v = 1, i = 1; i <= n; i++) {
                v *= i;
                if (k < v) {
                    int res = 0;
                    int m = (int)(n - i);
                    int id = -1;
                    //Console.WriteLine("dfs: {0} {1}", m, res);
                    for (int j = 0; j < num.Count; j++) {
                        if (num[j] > m) {
                            res += j;
                            id = j;
                            break;
                        }
                        if (j == num.Count - 1) {
                            Console.WriteLine(num.Count);
                            return;
                        }
                    }
                    //Console.WriteLine("dfs: {0} {1}", m, res);
                    for (int j = m; j < n; j++) {
                        val.Add(j + 1);
                    }
                    Console.WriteLine(dfs(m+1, k) + res);
                    return;
                }
            }
        }
    }
}


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

namespace _LuckyPermutation
{
    public class Puzzle
    {
        private static readonly List<int> Lucky = GetLuckyNumbers(6);

        static List<int> GetLuckyNumbers(int length)
        {
            var strNums = new List<string> { "4", "7" };
            while (strNums[strNums.Count - 1].Length < length)
            {
                var count = strNums.Count;
                for (var i = 0; i < count; i++)
                {
                    strNums.Add(strNums[i] + "4");
                    strNums.Add(strNums[i] + "7");
                }
            }

            return strNums.Select(int.Parse).ToList();
        }

        private static readonly long[] Factorials =
            new[] { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800 };

        public static int[] FindPerm(int n, int k)
        {
            if (k < 1 || (n < Factorials.Count() && k > Factorials[n]) || k > 1000000000) return null;
            var perm = new List<int> { 0 };

            var pos = 1L;
            for (var i = n; i > 0; i--)
            {
                var f = (i > Factorials.Count()) ? Factorials[Factorials.Count() - 1] : Factorials[i - 1];
                for (var j = 1; j <= n; j++)
                {
                    if (perm.Contains(j)) continue;

                    if (pos + f > k)
                    {
                        perm.Add(j);
                        break;
                    }
                    pos += f;
                }
            }

            return perm.ToArray();
        }

        public static int CountLucky(int[] seq)
        {
            if (seq == null) return -1;

            var count = 0;
            for (var j = 1; j < seq.Count(); j++)
            {
                if (Lucky.Contains(j) && Lucky.Contains(seq[j])) count++;
                //Console.Write("{0},", seq[j]);
            }
            //Console.WriteLine(count);
            //Console.WriteLine();

            return count;
        }
    }

    class ProgramLuckyPermutation
    {
        static void Main(/*string[] args*/)
        {
            var result = Console.ReadLine();
            if (result == null) return;
            var strnk = result.Split();
            var n = Convert.ToInt32(strnk[0]);  // permutation of integers between 1 and n
            var k = Convert.ToInt32(strnk[1]);  // lexicographical number of the permutation

            var seq = Puzzle.FindPerm(n, k);
            Console.WriteLine(Puzzle.CountLucky(seq));
        }
    }
}


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

namespace _LuckyPermutation
{
    public class Puzzle
    {
        private static readonly List<int> Lucky = GetLuckyNumbers(6);

        static List<int> GetLuckyNumbers(int length)
        {
            var strNums = new List<string> { "4", "7" };
            while (strNums[strNums.Count - 1].Length < length)
            {
                var count = strNums.Count;
                for (var i = 0; i < count; i++)
                {
                    strNums.Add(strNums[i] + "4");
                    strNums.Add(strNums[i] + "7");
                }
            }

            return strNums.Select(int.Parse).ToList();
        }

        private static readonly long[] Factorials =
            new[] { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800 };

        public static int[] FindPerm(int n, int k)
        {
            if (k < 1 || (n < Factorials.Count() && k > Factorials[n]) || k > 1000000000) return null;
            var perm = new HashSet<int> { 0 };

            var nseq = n;   // number of non-sequential elements
            if (n > 13)
            {
                nseq = 0;
                for (var i=1; i<Factorials.Count(); i++)
                {
                    if (k >= Factorials[i] && k < Factorials[i+1])
                    {
                        nseq = i + 1;
                        break;
                    }
                }
                for (var i=1; i<=n-nseq; i++)
                {
                    perm.Add(i);
                }
            }

            var pos = 1L;
            for (var i = nseq; i > 0; i--)
            {
                var f = (i > Factorials.Count()) ? Factorials[Factorials.Count() - 1] : Factorials[i - 1];
                for (var j = (n - nseq + 1); j <= n; j++)
                {
                    if (perm.Contains(j)) continue;

                    if (pos + f > k)
                    {
                        perm.Add(j);
                        break;
                    }
                    pos += f;
                }
            }

            return perm.ToArray();
        }

        public static int CountLucky(int[] seq)
        {
            if (seq == null) return -1;

            var count = 0;
            for (var j = 1; j < seq.Count(); j++)
            {
                if (Lucky.Contains(j) && Lucky.Contains(seq[j]))
                {
                    count++;
                }
                //Console.Write("{0},", seq[j]);
            }
            //Console.WriteLine(count);
            //Console.WriteLine();

            return count;
        }
    }

    class ProgramLuckyPermutation
    {
        static void Main(/*string[] args*/)
        {
            var result = Console.ReadLine();
            if (result == null) return;
            var strnk = result.Split();
            var n = Convert.ToInt32(strnk[0]);  // permutation of integers between 1 and n
            var k = Convert.ToInt32(strnk[1]);  // lexicographical number of the permutation

            var seq = Puzzle.FindPerm(n, k);
            Console.WriteLine(Puzzle.CountLucky(seq));
        }
    }
}


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

namespace ProgrammingContest.Codeforces.Round91 {
    class C {
        static List<int> num = new List<int>();
        static void gen(long x, int n) {
            if (x <= n) {
                if(x != 0)
                    num.Add((int)x);
                gen(x * 10 + 4, n);
                gen(x * 10 + 7, n);
            }
        }

        static long fact(long n) { long res = 1; while (n > 1) res *= n--; return res; }

        static int n;
        static List<int> val = new List<int>();
        static int dfs(int pos, long k) {
            if (pos > n) return 0;
            int rest = n - pos,
                res = 0;
            for (int i = 0; i < val.Count; i++) {
                if (val[i] == -1) continue;
                if (k < fact(rest)) {
                    if (num.Contains(val[i]) && num.Contains(pos)) {
                        res = 1;
                    }
                    //Console.WriteLine("dfs: {0} {1}", pos, val[i]);
                    val[i] = -1;
                    return res + dfs(pos + 1, k);
                }
                k -= fact(rest);
            }
            throw new Exception();
        }

        static void Main() {
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            n = xs[0];
            int k = xs[1]-1;

            for (int v = k, i = 1; i <= n && v != 0; i++) {
                v /= i;
                if (i == n && v != 0) {
                    Console.WriteLine(-1);
                    return;
                }
            }

            gen(0, n);
            num.Sort();
            for (long v = 1, i = 1; i <= n; i++) {
                v *= i;
                if (k < v) {
                    int res = 0;
                    int m = (int)(n - i);
                    int id = -1;
                    //Console.WriteLine("dfs: {0} {1}", m, res);
                    for (int j = 0; j < num.Count; j++) {
                        if (num[j] > m) {
                            res += j;
                            id = j;
                            break;
                        }
                        if (j == num.Count - 1) {
                            Console.WriteLine(num.Count);
                            return;
                        }
                    }
                    //Console.WriteLine("dfs: {0} {1}", m, res);
                    for (int j = m; j < n; j++) {
                        val.Add(j + 1);
                    }
                    Console.WriteLine(dfs(m+1, k) + res);
                    return;
                }
            }
        }
    }
}


using System;

namespace consap1
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            String[] inp = Console.ReadLine().Split();
            int Ax = int.Parse(inp[0]), Ay = int.Parse(inp[1]),
            Bx = int.Parse(inp[2]), By = int.Parse(inp[3]),
            Cx = int.Parse(inp[4]), Cy = int.Parse(inp[5]);
            if (Math.Pow(Ax - Bx, 2) + Math.Pow(Ay - By, 2) == Math.Pow(Cx - Bx, 2) + Math.Pow(Cy - By, 2)) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


using System;

namespace consap1
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            String[] inp = Console.ReadLine().Split();
            long Ax = long.Parse(inp[0]), Ay = long.Parse(inp[1]),
            Bx = long.Parse(inp[2]), By = long.Parse(inp[3]),
            Cx = long.Parse(inp[4]), Cy = long.Parse(inp[5]);
            if ((Ax - Bx)*(Ax - Bx) + (Ay - By)*(Ay - By) == (Cx - Bx) * (Cx - Bx) + (Cy - By) * (Cy - By)) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


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

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

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

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

        public void Solve()
        {
            var x1 = sr.NextInt64();
            var y1 = sr.NextInt64();
            var x2 = sr.NextInt64();
            var y2 = sr.NextInt64();
            var x3 = sr.NextInt64();
            var y3 = sr.NextInt64();
            if (Cross(x1, y1, x2, y2, x3, y3) == 0) {
                sw.WriteLine("No");
                return;
            }
            var d1 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
            var d2 = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
            if (d1 == d2) {
                sw.WriteLine("Yes");
            }
            else {
                sw.WriteLine("No");
            }
        }

        private long Cross(long x1, long y1, long x2, long y2, long x, long y)
        {
            return (x1 - x) * (y2 - y) - (x2 - x) * (y1 - y);
        }

        ~Task()
        {
            Dispose(false);
        }

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

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

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

                isDispose = true;
            }
        }
    }
}

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

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

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

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

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

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

        return buffer[seek++];
    }

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

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

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

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

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

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

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

            isDispose = true;
        }
    }

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


using System;
class Program
    {
        public static void Main(string[] args)
        {
            long[] dt;
            //string[] input = Console.In.ReadLine().Split(new char[] { '\t', ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            {
                dt = new long[3];
                string[] inp = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                dt[0] = long.Parse(inp[0]);
                dt[1] = long.Parse(inp[1]);
                dt[2] = 1L;
                if(dt[1]==4)
                {
                    dt[2] += (dt[0] - 1L) * (dt[0] - 2L) * dt[0] * (dt[0] - 3L) * 9L / 24L;
                    dt[1]--;
                }
            }
            {
                long temp = dt[0] * dt[0] - dt[0];
                dt[0]--;
                for (long temp2 = 2L, cntr = 2L; cntr <=dt[1];)
                {
                    dt[2] += ((temp * temp2 / cntr) / temp2);
                    temp *= --dt[0];
                    temp2 *= ++cntr;
                }
            }
            Console.WriteLine(dt[2]);
        }

    }


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

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

	class MainClass
	{
		public static void Main(string[] args) {
			int[] a = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray();
			int x1 = a [0], y1 = a [1], x2 = a [2], y2 = a [3];
			int r1 = x2 - x1 + 1;
			int r2 = y2 - y1 + 1;
			long ans = (r2 / 2L) * r1;
			if (r2 % 2 == 1)
				ans += (r1 + 1L) / 2L;
			Console.WriteLine (ans);
		}
	}
}


using System;
using System.Collections.Generic;
using System.Numerics;

namespace TempProject
{
    class Program
    {
        static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            BigInteger x1 = BigInteger.Parse(s[0]),
                       y1 = BigInteger.Parse(s[1]),
                       x2 = BigInteger.Parse(s[2]),
                       y2 = BigInteger.Parse(s[3]);
            BigInteger col = (y2 - y1) / 2 + 1,
                       ln = (x2 - x1) / 2 + 1;
            BigInteger sum = col * ln + (col - 1) * (ln - 1);
            Console.WriteLine(sum);
            //Console.ReadKey();;

        }
    }
}