using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var q = sc.Integer();
            var par = new int[500002];
            par[0] = -1;
            var dp = Enumerate(500002, x => new double[45]);
            for (int i = 1; i < 45; i++)
                dp[0][i] = 1.0;

            var ptr = 1;
            Action<int> recalc = null;
            recalc = v =>
              {
                  for (int h = 1; h < 40; h++)
                      dp[v][h] = 1.0;
                  var ps = new List<int>();
                  for (int h = 0; h <= 40; h++)
                  {
                      if (v == -1) break;
                      ps.Add(v);
                      v = par[v];
                  }
                  for (int i = ps.Count - 2; i > 0; i--)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] /= (dp[u][h] + 1) / 2;
                  }
                  for (int i = 0; i + 1 < ps.Count; i++)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] *= (dp[u][h] + 1) / 2;
                  }
              };
            for (int i = 0; i < q; i++)
            {
                if (sc.Integer() == 1)
                {
                    var p = sc.Integer() - 1;
                    par[ptr] = p;
                    recalc(ptr);
                    ptr++;

                }
                else
                {
                    var v = sc.Integer() - 1;
                    var ans = 0.0;
                    for (int h = 1; h < 40; h++)
                        ans += 1 - dp[v][h];
                    Debug.WriteLine(dp[v].AsJoinedString());
                    IO.Printer.Out.WriteLine(ans);

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

#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

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


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var q = sc.Integer();
            var par = new int[500000];
            par[0] = -1;
            var dp = Enumerate(500000, x => new double[35]);
            for (int i = 1; i < 35; i++)
                dp[0][i] = 1.0;

            var ptr = 1;
            Action<int> recalc = null;
            recalc = v =>
              {
                  for (int h = 1; h < 35; h++)
                      dp[v][h] = 1.0;
                  var ps = new List<int>();
                  for (int h = 0; h <= 35; h++)
                  {
                      if (v == -1) break;
                      ps.Add(v);
                      v = par[v];
                  }
                  for (int i = ps.Count - 2; i > 0; i--)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] /= (dp[u][h] + 1) / 2;
                  }
                  for (int i = 0; i + 1 < ps.Count; i++)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] *= (dp[u][h] + 1) / 2;
                  }
              };
            for (int i = 0; i < q; i++)
            {
                if (sc.Integer() == 1)
                {
                    var p = sc.Integer() - 1;
                    par[ptr] = p;
                    recalc(ptr);
                    ptr++;

                }
                else
                {
                    var v = sc.Integer() - 1;
                    var ans = 0.0;
                    for (int h = 1; h < 35; h++)
                        ans += 1 - dp[v][h];
                    Debug.WriteLine(dp[v].AsJoinedString());
                    IO.Printer.Out.WriteLine(ans);

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

#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

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


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var q = sc.Integer();
            var par = new int[500002];
            par[0] = -1;
            var dp = Enumerate(500002, x => new double[35]);
            for (int i = 1; i < 35; i++)
                dp[0][i] = 1.0;

            var ptr = 1;
            Action<int> recalc = null;
            recalc = v =>
              {
                  for (int h = 1; h < 35; h++)
                      dp[v][h] = 1.0;
                  var ps = new List<int>();
                  for (int h = 0; h <= 35; h++)
                  {
                      if (v == -1) break;
                      ps.Add(v);
                      v = par[v];
                  }
                  for (int i = ps.Count - 2; i > 0; i--)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] /= (dp[u][h] + 1) / 2;
                  }
                  for (int i = 0; i + 1 < ps.Count; i++)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] *= (dp[u][h] + 1) / 2;
                  }
              };
            for (int i = 0; i < q; i++)
            {
                if (sc.Integer() == 1)
                {
                    var p = sc.Integer() - 1;
                    par[ptr] = p;
                    recalc(ptr);
                    ptr++;

                }
                else
                {
                    var v = sc.Integer() - 1;
                    var ans = 0.0;
                    for (int h = 1; h < 35; h++)
                        ans += 1 - dp[v][h];
                    Debug.WriteLine(dp[v].AsJoinedString());
                    IO.Printer.Out.WriteLine(ans);

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

#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

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


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var q = sc.Integer();
            var par = new int[500000];
            par[0] = -1;
            var dp = Enumerate(500000, x => new double[35]);
            for (int i = 1; i < 35; i++)
                dp[0][i] = 1.0;

            var ptr = 1;
            Action<int> recalc = null;
            recalc = v =>
              {
                  for (int h = 1; h < 35; h++)
                      dp[v][h] = 1.0;
                  var ps = new List<int>();
                  for (int h = 0; h <= 35; h++)
                  {
                      if (v == -1) break;
                      ps.Add(v);
                      v = par[v];
                  }
                  for (int i = ps.Count - 2; i > 0; i--)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] /= (dp[u][h] + 1) / 2;
                  }
                  for (int i = 0; i + 1 < ps.Count; i++)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] *= (dp[u][h] + 1) / 2;
                  }
              };
            for (int i = 0; i < q; i++)
            {
                if (sc.Integer() == 1)
                {
                    var p = sc.Integer() - 1;
                    par[ptr] = p;
                    recalc(ptr);
                    ptr++;

                }
                else
                {
                    var v = sc.Integer() - 1;
                    var ans = 0.0;
                    for (int h = 1; h < 35; h++)
                        ans += dp[v][h] - dp[v][h - 1];
                    Debug.WriteLine(dp[v].AsJoinedString());
                    IO.Printer.Out.WriteLine(ans);

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

#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

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


using System;
using CompLib.Collections.Generic;
using CompLib.Util;

public class Program
{
    private int N, M, A, B;
    private int G0, X, Y, Z;

    private long[] H;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();
        G0 = sc.NextInt();
        X = sc.NextInt();
        Y = sc.NextInt();
        Z = sc.NextInt();

        /*
         * N*Mグリッド
         * セル(i,j) は高さH[i,j]
         *
         * 画面には a*bの範囲が収まる
         *
         * 表示されてる範囲で最小のHの総和
         *
         *
         * g_i = (g_{i-1}*x+y) % Z
         * H[i,j] = g_{(i-1)*m+j-1}
         */

        var st = new SegmentTree[N];
        for (int i = 0; i < N; i++)
        {
            int[] row = new int[M];
            if (i == 0)
            {
                row[0] = G0;
            }
            else
            {
                row[0] = (int) (((long) st[i - 1][M - 1] * X + Y) % Z);
            }

            for (int j = 1; j < M; j++)
            {
                row[j] = (int) (((long) row[j - 1] * X + Y) % Z);
            }

            st[i] = new SegmentTree(row);
        }

        long ans = 0;
        for (int j = 0; j + B <= M; j++)
        {
            var col = new int[N];
            for (int i = 0; i < N; i++)
            {
                col[i] = st[i].Query(j, j + B);
            }

            var st2 = new SegmentTree(col);
            for (int i = 0; i + A <= N; i++)
            {
                ans += st2.Query(i, i + A);
            }
        }

        Console.WriteLine(ans);
    }

    int Conv(int i, int j)
    {
        return i * M + j;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Collections.Generic
{
    using System;

    public class SegmentTree
    {
        private const int N = 4096;
        private int[] _array;

        private const int _identity = int.MaxValue;

        public SegmentTree(int[] a)
        {
            _array = new int[N * 2];
            for (int i = 0; i < a.Length; i++)
            {
                _array[i + N] = a[i];
            }

            for (int i = a.Length; i < N; i++)
            {
                _array[i + N] = _identity;
            }

            for (int i = N - 1; i >= 1; i--)
            {
                _array[i] = Math.Min(_array[i * 2], _array[i * 2 + 1]);
            }
        }

        /// <summary>
        /// A[i]をnに更新 O(log N)
        /// </summary>
        /// <param name="i"></param>
        /// <param name="n"></param>
        public void Update(int i, int n)
        {
            i += N;
            _array[i] = n;
            while (i > 1)
            {
                i /= 2;
                _array[i] = System.Math.Min(_array[i * 2], _array[i * 2 + 1]);
            }
        }

        private int Query(int left, int right, int k, int l, int r)
        {
            if (r <= left || right <= l)
            {
                return _identity;
            }

            if (left <= l && r <= right)
            {
                return _array[k];
            }

            return Math.Min(Query(left, right, k * 2, l, (l + r) / 2),
                Query(left, right, k * 2 + 1, (l + r) / 2, r));
        }

        public int Root() => _array[1];

        /// <summary>
        /// A[left] op A[left+1] ... op A[right-1]を求める
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public int Query(int left, int right)
        {
            return Query(left, right, 1, 0, N);
        }

        public int this[int i]
        {
            set { Update(i, value); }
            get { return _array[i + N]; }
        }
    }
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


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

class Solution
{
	class SlideMin
	{
		LinkedList<int> lst = new LinkedList<int>();
		public void Push(int x)
		{
			while (lst.Count() > 0 && lst.Last() > x) lst.RemoveLast();
			lst.AddLast(x);
		}
		public void Pop(int x)
		{
			if (lst.Count() > 0 && lst.First() == x) lst.RemoveFirst();
		}
		public int Top()
		{
			return lst.First();
		}
	};

	int n, m, a, b;
	int[,] M;

	void Make(int g, int x, int y, int z)
	{
		M = new int[n, m];
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				M[i, j] = g;
				g = (int)(((long)g * x + y) % z);
			}
		}
	}

	void Run()
	{
		var A = Array.ConvertAll(cin.ReadLine().Split(), int.Parse);
		n = A[0]; m = A[1]; a = A[2]; b = A[3];
		A = Array.ConvertAll(cin.ReadLine().Split(), int.Parse);
		Make(A[0], A[1], A[2], A[3]);

		int[,] MinRow = new int[n, m - b + 1];
		for (int i = 0; i < n; i++)
		{
			SlideMin slide = new SlideMin();
			for (int j = 0; j < b; j++)
			{
				slide.Push(M[i, j]);
			}
			for (int j = 0; j < m - b + 1; j++)
			{
				MinRow[i, j] = slide.Top();
				if (j == m - b) break;
				slide.Pop(M[i, j]);
				slide.Push(M[i, j + b]);
			}
		}

		long ans = 0;
		for (int j = 0; j < m - b + 1; j++)
		{
			SlideMin slide = new SlideMin();
			for (int i = 0; i < a; i++)
			{
				slide.Push(MinRow[i, j]);
			}
			for (int i = 0; i < n - a + 1; i++)
			{
				ans += slide.Top();
				if (i == n - a) break;
				slide.Pop(MinRow[i, j]);
				slide.Push(MinRow[i + a, j]);
			}
		}

		cout.Write(ans);
	}

	static TextReader cin;
	static TextWriter cout;

	static void Main()
	{
#if NARUT_LOCAL
		cin = new StreamReader("io/test.in", Encoding.ASCII);
#else
		cin = new StreamReader(Console.OpenStandardInput(), Encoding.ASCII);
#endif
		cout = new StreamWriter(Console.OpenStandardOutput(), Encoding.ASCII) { AutoFlush = false };
		(new Solution()).Run();
		cin.Close();
		cout.Close();
	}
}


using System;
using CompLib.Collections.Generic;
using CompLib.Util;

public class Program
{
    private int N, M, A, B;
    private int G0, X, Y, Z;

    private long[] H;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();
        G0 = sc.NextInt();
        X = sc.NextInt();
        Y = sc.NextInt();
        Z = sc.NextInt();

        /*
         * N*Mグリッド
         * セル(i,j) は高さH[i,j]
         *
         * 画面には a*bの範囲が収まる
         *
         * 表示されてる範囲で最小のHの総和
         *
         *
         * g_i = (g_{i-1}*x+y) % Z
         * H[i,j] = g_{(i-1)*m+j-1}
         */

        H = new long[N * M];
        H[0] = G0;
        for (int i = 1; i < N * M; i++)
        {
            H[i] = (H[i - 1] * X + Y) % Z;
        }

        var st = new SegmentTree[N];
        for (int i = 0; i < N; i++)
        {
            st[i] = new SegmentTree(M);
            for (int j = 0; j < M; j++)
            {
                st[i][j] = (int) H[Conv(i, j)];
            }
        }

        long ans = 0;
        for (int j = 0; j + B <= M; j++)
        {
            var st2 = new SegmentTree(A);
            for (int i = 0; i < A - 1; i++) st2[i] = st[i].Query(j, j + B);
            for (int i = A - 1; i < N; i++)
            {
                st2[i % A] = st[i].Query(j, j + B);
                ans += st2.Root();
            }
        }

        Console.WriteLine(ans);
    }

    int Conv(int i, int j)
    {
        return i * M + j;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Collections.Generic
{
    using System;

    public class SegmentTree
    {
        private readonly int N;
        private int[] _array;

        private const int _identity = int.MaxValue;

        public SegmentTree(int size)
        {
            N = 1;
            while (N < size) N *= 2;

            _array = new int[N * 2];
            for (int i = 1; i < N * 2; i++)
            {
                _array[i] = _identity;
            }
        }

        /// <summary>
        /// A[i]をnに更新 O(log N)
        /// </summary>
        /// <param name="i"></param>
        /// <param name="n"></param>
        public void Update(int i, int n)
        {
            i += N;
            _array[i] = n;
            while (i > 1)
            {
                i /= 2;
                _array[i] = System.Math.Min(_array[i * 2], _array[i * 2 + 1]);
            }
        }

        private int Query(int left, int right, int k, int l, int r)
        {
            if (r <= left || right <= l)
            {
                return _identity;
            }

            if (left <= l && r <= right)
            {
                return _array[k];
            }

            return Math.Min(Query(left, right, k * 2, l, (l + r) / 2),
                Query(left, right, k * 2 + 1, (l + r) / 2, r));
        }

        public int Root() => _array[1];

        /// <summary>
        /// A[left] op A[left+1] ... op A[right-1]を求める
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public int Query(int left, int right)
        {
            return Query(left, right, 1, 0, N);
        }

        public int this[int i]
        {
            set { Update(i, value); }
            get { return _array[i + N]; }
        }
    }
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


using CompLib.Util;
using System;
using System.Collections.Generic;

public class Program
{
    private int N, M, A, B;
    private int G0, X, Y, Z;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();

        G0 = sc.NextInt();
        X = sc.NextInt();
        Y = sc.NextInt();
        Z = sc.NextInt();

        long[] H = new long[N * M];
        H[0] = G0;
        for (int i = 1; i < N * M; i++)
        {
            H[i] = (H[i - 1] * X + Y) % Z;
        }

        MinimumQueue[] q = new MinimumQueue[N];
        for (int i = 0; i < N; i++)
        {
            q[i] = new MinimumQueue();
            for (int j = 0; j < B - 1; j++)
            {
                q[i].Enqueue(H[i * M + j]);
            }
        }

        long ans = 0;
        for (int j = B - 1; j < M; j++)
        {
            var q2 = new MinimumQueue();
            for (int i = 0; i < N; i++)
            {
                q[i].Enqueue(H[i * M + j]);
                q2.Enqueue(q[i].Min());
                if (i >= A - 1)
                {
                    ans += q2.Min();
                    q2.Dequeue();
                }
                q[i].Dequeue();
            }
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

class MinimumStack
{
    private readonly Stack<(long num, long min)> stack;

    public MinimumStack()
    {
        stack = new Stack<(long num, long min)>();
    }

    public void Push(long num)
    {
        if (Count == 0) stack.Push((num, num));
        else stack.Push((num, Math.Min(num, stack.Peek().min)));
    }

    public long Peek()
    {
        return stack.Peek().num;
    }

    public long Pop()
    {
        return stack.Pop().num;
    }

    public long Min()
    {
        return Count == 0 ? long.MaxValue : stack.Peek().min;
    }

    public int Count => stack.Count;
}

class MinimumQueue
{
    private readonly MinimumStack s1, s2;

    public MinimumQueue()
    {
        s1 = new MinimumStack();
        s2 = new MinimumStack();
    }

    public void Enqueue(long l)
    {
        s2.Push(l);
    }

    private void Exec()
    {
        if (s1.Count == 0)
        {
            while (s2.Count > 0)
            {
                s1.Push(s2.Pop());
            }
        }
    }

    public long Peek()
    {
        Exec();
        return s1.Peek();
    }

    public long Dequeue()
    {
        Exec();
        return s1.Pop();
    }

    public long Min()
    {
        return Math.Min(s1.Min(), s2.Min());
    }

    public int Count => s1.Count + s2.Count;
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


using System;
using CompLib.Collections.Generic;
using CompLib.Util;

public class Program
{
    private int N, M, A, B;
    private int G0, X, Y, Z;

    private long[] H;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();
        G0 = sc.NextInt();
        X = sc.NextInt();
        Y = sc.NextInt();
        Z = sc.NextInt();

        /*
         * N*Mグリッド
         * セル(i,j) は高さH[i,j]
         *
         * 画面には a*bの範囲が収まる
         *
         * 表示されてる範囲で最小のHの総和
         *
         *
         * g_i = (g_{i-1}*x+y) % Z
         * H[i,j] = g_{(i-1)*m+j-1}
         */

        H = new long[N * M];
        H[0] = G0;
        for (int i = 1; i < N * M; i++)
        {
            H[i] = (H[i - 1] * X + Y) % Z;
        }

        var st = new SegmentTree<long>[N];
        for (int i = 0; i < N; i++)
        {
            st[i] = new SegmentTree<long>(M, Math.Min, long.MaxValue);
            for (int j = 0; j < M; j++)
            {
                st[i][j] = H[Conv(i, j)];
            }
        }

        long ans = 0;
        for (int j = 0; j + B <= M; j++)
        {
            var st2 = new SegmentTree<long>(A, Math.Min, long.MaxValue);
            for (int i = 0; i < A - 1; i++) st2[i] = st[i].Query(j, j + B);
            for (int i = A - 1; i < N; i++)
            {
                st2[i % A] = st[i].Query(j, j + B);
                ans += st2.Root();
            }
        }

        Console.WriteLine(ans);
    }

    int Conv(int i, int j)
    {
        return i * M + j;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Collections.Generic
{
    using System;

    public class SegmentTree<T>
    {
        private readonly int N;
        private T[] _array;

        private T _identity;
        private Func<T, T, T> _operation;

        public SegmentTree(int size, Func<T, T, T> operation, T identity)
        {
            N = 1;
            while (N < size) N *= 2;
            _identity = identity;
            _operation = operation;
            _array = new T[N * 2];
            for (int i = 1; i < N * 2; i++)
            {
                _array[i] = _identity;
            }
        }

        /// <summary>
        /// A[i]をnに更新 O(log N)
        /// </summary>
        /// <param name="i"></param>
        /// <param name="n"></param>
        public void Update(int i, T n)
        {
            i += N;
            _array[i] = n;
            while (i > 1)
            {
                i /= 2;
                _array[i] = _operation(_array[i * 2], _array[i * 2 + 1]);
            }
        }

        private T Query(int left, int right, int k, int l, int r)
        {
            if (r <= left || right <= l)
            {
                return _identity;
            }

            if (left <= l && r <= right)
            {
                return _array[k];
            }

            return _operation(Query(left, right, k * 2, l, (l + r) / 2),
                Query(left, right, k * 2 + 1, (l + r) / 2, r));
        }

        public T Root() => _array[1];

        /// <summary>
        /// A[left] op A[left+1] ... op A[right-1]を求める
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public T Query(int left, int right)
        {
            return Query(left, right, 1, 0, N);
        }

        public T this[int i]
        {
            set { Update(i, value); }
            get { return _array[i + N]; }
        }
    }
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Collections.Generic;

public class Program
{
    private int N, M, A, B;
    private int G0, X, Y, Z;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();

        long[] g = new long[N * M];
        g[0] = sc.NextInt();
        X = sc.NextInt();
        Y = sc.NextInt();
        Z = sc.NextInt();
        for (int i = 1; i < N * M; i++)
        {
            g[i] = (g[i - 1] * X + Y) % Z;
        }

        long[][] t = new long[N][];
        for (int i = 0; i < N; i++)
        {
            t[i] = new long[M];
            for (int j = 0; j < M; j++)
            {
                t[i][j] = g[i * M + j];
            }
        }

        var mq = new MinQueue[N];
        for (int i = 0; i < N; i++)
        {
            mq[i] = new MinQueue();
        }

        for (int j = 0; j < B - 1; j++)
        {
            for (int i = 0; i < N; i++)
            {
                mq[i].Enqueue(t[i][j]);
            }
        }

        long ans = 0;
        for (int j = B - 1; j < M; j++)
        {
            for (int i = 0; i < N; i++)
            {
                mq[i].Enqueue(t[i][j]);
            }

            var mq2 = new MinQueue();
            for (int i = 0; i < A - 1; i++)
            {
                mq2.Enqueue(mq[i].GetMin());
            }

            for (int i = A - 1; i < N; i++)
            {
                mq2.Enqueue(mq[i].GetMin());
                ans += mq2.GetMin();
                mq2.Dequeue();
            }

            for (int i = 0; i < N; i++)
            {
                mq[i].Dequeue();
            }
        }

        Console.WriteLine(ans);
    }

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

namespace CompLib.Collections.Generic
{
    using System;
    using System.Diagnostics;

    public class SegmentTree<T>
    {
        // 見かけ上の大きさ、実際の大きさ
        private readonly int _n, _size;
        private T[] _array;

        private T _identity;
        private Func<T, T, T> _operation;

        public SegmentTree(int n, Func<T, T, T> operation, T identity)
        {
            _n = n;
            _size = 1;
            while (_size < _n)
            {
                _size *= 2;
            }

            _identity = identity;
            _operation = operation;
            _array = new T[_size * 2];
            for (int i = 1; i < _size * 2; i++)
            {
                _array[i] = _identity;
            }
        }

        public SegmentTree(T[] a, Func<T, T, T> operation, T identity)
        {
            _n = a.Length;
            _size = 1;
            while (_size < _n)
            {
                _size *= 2;
            }

            _identity = identity;
            _operation = operation;
            _array = new T[_size * 2];
            for (int i = 0; i < a.Length; i++)
            {
                _array[i + _size] = a[i];
            }

            for (int i = a.Length; i < _size; i++)
            {
                _array[i + _size] = identity;
            }

            for (int i = _size - 1; i >= 1; i--)
            {
                _array[i] = operation(_array[i * 2], _array[i * 2 + 1]);
            }
        }

        /// <summary>
        /// A[i]をnに更新 O(log N)
        /// </summary>
        /// <param name="i"></param>
        /// <param name="n"></param>
        public void Update(int i, T n)
        {
            Debug.Assert(0 <= i && i < _n);
            i += _size;
            _array[i] = n;
            while (i > 1)
            {
                i /= 2;
                _array[i] = _operation(_array[i * 2], _array[i * 2 + 1]);
            }
        }

        /// <summary>
        /// A[left] op A[left+1] ... op A[right-1]を求める
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public T Query(int left, int right)
        {
            Debug.Assert(0 <= left && left <= right && right <= _n);
            T sml = _identity;
            T smr = _identity;

            left += _size;
            right += _size;
            while (left < right)
            {
                if ((left & 1) != 0) sml = _operation(sml, _array[left++]);
                if ((right & 1) != 0) smr = _operation(_array[--right], smr);
                left >>= 1;
                right >>= 1;
            }

            return _operation(sml, smr);
        }

        /// <summary>
        /// op(a[0],a[1],...,a[n-1])を返します
        /// </summary>
        /// <returns></returns>
        public T All()
        {
            return _array[1];
        }

        /// <summary>
        /// f(op(a[l],a[l+1],...a[r-1])) = trueとなる最大のrを返します
        /// </summary>
        /// <param name="l"></param>
        /// <param name="f"></param>
        /// <returns></returns>
        public int MaxRight(int l, Func<T, bool> f)
        {
            Debug.Assert(0 <= l && l <= _n);
#if DEBUG
            Debug.Assert(f(_identity));
#endif
            if (l == _n) return _n;
            l += _size;
            T sm = _identity;
            do
            {
                while (l % 2 == 0) l >>= 1;
                if (!f(_operation(sm, _array[l])))
                {
                    while (l < _size)
                    {
                        l <<= 1;
                        if (f(_operation(sm, _array[l])))
                        {
                            sm = _operation(sm, _array[l]);
                            l++;
                        }
                    }

                    return l - _size;
                }

                sm = _operation(sm, _array[l]);
                l++;
            } while ((l & -l) != l);

            return _n;
        }

        /// <summary>
        /// f(op(a[l],a[l+1],...a[r-1])) = trueとなる最小のlを返します
        /// </summary>
        /// <param name="r"></param>
        /// <param name="f"></param>
        /// <returns></returns>
        public int MinLeft(int r, Func<T, bool> f)
        {
            Debug.Assert(0 <= r && r <= _n);
#if DEBUG
            Debug.Assert(f(_identity));
#endif
            if (r == 0) return 0;
            r += _size;
            T sm = _identity;

            do
            {
                r--;
                while (r > 1 && (r % 2 != 0)) r >>= 1;
                if (!f(_operation(_array[r], sm)))
                {
                    while (r < _size)
                    {
                        r = (2 * r + 1);
                        if (f(_operation(_array[r], sm)))
                        {
                            sm = _operation(_array[r], sm);
                            r--;
                        }
                    }

                    return r + 1 - _size;
                }

                sm = _operation(_array[r], sm);
            } while ((r & -r) != r);

            return 0;
        }

        public T this[int i]
        {
            set { Update(i, value); }
            get
            {
                Debug.Assert(0 <= i && i < _n);
                return _array[i + _size];
            }
        }
    }
}

class MinStack
{
    private Stack<(long val, long min)> S;

    public MinStack()
    {
        S = new Stack<(long val, long min)>();
    }

    public long GetMin()
    {
        if (S.Count == 0) return long.MaxValue;
        return S.Peek().min;
    }

    public void Push(long val)
    {
        S.Push((val, Math.Min(val, GetMin())));
    }

    public long Pop()
    {
        return S.Pop().val;
    }

    public int Count
    {
        get { return S.Count; }
    }
}

class MinQueue
{
    public MinStack L, R;

    public MinQueue()
    {
        L = new MinStack();
        R = new MinStack();
    }

    public void Enqueue(long val)
    {
        R.Push(val);
    }

    public void Dequeue()
    {
        if (L.Count == 0)
        {
            while (R.Count > 0)
            {
                L.Push(R.Pop());
            }
        }

        L.Pop();
    }

    public long GetMin()
    {
        return Math.Min(L.GetMin(), R.GetMin());
    }
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


/*
csc -debug E.cs && mono --debug E.exe <<< "3 4 2 1
1 2 3 59"
*/

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

public struct QueueItem {
    public ulong Val;
    public int Index;
}

public class HelloWorld {
    public static void SolveCodeForces() {
        var n = cin.NextInt();
        var m = cin.NextInt();
        var a = cin.NextInt();
        var b = cin.NextInt();

        var Arr = Helpers.CreateArray(n, _ => new ulong[m]);
        {
            var g0 = cin.NextUlong();
            var x = cin.NextUlong();
            var y = cin.NextUlong();
            var z = cin.NextUlong();
            for (var i = 0; i < n; i++)
                for (var j = 0; j < m; j++) {
                    Arr[i][j] = g0;
                    g0 = (g0 * x + y) % z;
                }
        }

// System.Console.WriteLine("Arr:");
// foreach (var row in Arr)
//     System.Console.WriteLine(row.Join());

        var QVers = new Deque<QueueItem>[m];
        for (var j = 0; j < m; j++) {
            var Q = new Deque<QueueItem>();
            for (var i = 0; i < a; i++) {
                var x = Arr[i][j];
                AppendRight(Q, i, x);
            }
            QVers[j] = Q;
        }

        var ans = 0ul;

        for (var i = a - 1; i < n; i++) {
            var rowAns = 0ul;

            var Q = new Deque<QueueItem>();
            for (var j = 0; j < b; j++) {
                AppendRight(Q, j, QVers[j].Left.Val);
            }

            rowAns += Q.Left.Val;
            for (var j = b; j < m; j++) {
                Shift(Q, j - b);
                AppendRight(Q, j, QVers[j].Left.Val);
                rowAns += Q.Left.Val;
            }

            for (var j = 0; j < m; j++) {
                Shift(QVers[j], i - a + 1);
                if (i + 1 < n)
                    AppendRight(QVers[j], i + 1, Arr[i + 1][j]);
            }

// System.Console.WriteLine(new {i, rowAns});
            ans += rowAns;
        }
// System.Console.WriteLine(new {brute = SolveBrute(Arr, n, m, a, b)});

        System.Console.WriteLine(ans);
    }

    static ulong SolveBrute(ulong[][] Arr, int n, int m, int a, int b) {
        var ans = 0ul;

        for (var i = a-1; i < n; i++)
            for (var j = b-1; j < m; j++) {
                var min = Arr[i][j];
                for (var ii = 0; ii < a; ii++)
                    for (var jj = 0; jj < b; jj++)
                        min = Math.Min(min, Arr[i - ii][j - jj]);
                ans += min;
            }

        return ans;
    }

    static void AppendRight(Deque<QueueItem> Q, int i, ulong x) {
        while (Q.Count > 0 && Q.Right.Val >= x) Q.RemoveRight();
        Q.AppendRight(new QueueItem{ Val = x, Index = i });
    }

    static void Shift(Deque<QueueItem> Q, int i) {
        if (Q.Left.Index == i) Q.RemoveLeft();
    }

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

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

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public class Deque<T> : IEnumerable<T> {
    private T[] arr;
    private int index;
    private int count;
    private int n;

    public Deque(T[] arr) {
        this.arr = arr;
        n = arr.Length;
        count = arr.Length;
    }

    public Deque(int capacity = 8) {
        n = capacity;
        arr = new T[capacity];
    }

    public int Count => count;

    public T Left => this[0];
    public T Right => this[count - 1];

    public T this[int i] {
        get {
            if (i < 0 || i >= count) throw new InvalidOperationException(string.Format("Index {0} is out of range (count = {1})", i, count));
            return arr[(index + i) % n];
        }
    }

    public void AppendRight(T val) {
        EnsureSize();
        arr[(index + count) % n] = val;
        count++;
    }

    public void AppendLeft(T val) {
        EnsureSize();
        index = (index + n - 1) % n;
        arr[index] = val;
        count++;
    }

    public T RemoveLeft() {
        if (count == 0) throw new InvalidOperationException("Can't remove left because deque is empty");

        var result = arr[index];
        index = (index + 1) % n;
        count--;
        return result;
    }

    public T RemoveRight() {
        if (count == 0) throw new InvalidOperationException("Can't remove right because deque is empty");

        var result = arr[(index + count + n - 1) % n];
        count--;
        return result;
    }

    private void EnsureSize() {
        if (count == arr.Length) {
            var newArr = new T[arr.Length * 2];
            var left = Math.Min(count, arr.Length - index);
            Array.Copy(arr, index, newArr, 0, left);
            if (left < count)
                Array.Copy(arr, 0, newArr, left, count - left);
            arr = newArr;
            index = 0;
            n = newArr.Length;
        }
    }

    public IEnumerator<T> GetEnumerator()
    {
        for (var i = 0; i < count; i++) {
            yield return arr[(index + i) % n];
        }
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

public static class Helpers {
    public static string Join<T>(this IEnumerable<T> arr) {
        return string.Join(" ", arr);
    }

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

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

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

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

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

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

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

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

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

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

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


using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{
    private int N, M, A, B;
    private int G0, X, Y, Z;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();

        int[] g = new int[N * M];
        g[0] = sc.NextInt();
        X = sc.NextInt();
        Y = sc.NextInt();
        Z = sc.NextInt();
        for (int i = 1; i < N * M; i++)
        {
            g[i] = (int) (((long) g[i - 1] * X + Y) % Z);
        }

        var mq = new MinQueue[N];
        for (int i = 0; i < N; i++)
        {
            mq[i] = new MinQueue();
        }

        for (int j = 0; j < B - 1; j++)
        {
            for (int i = 0; i < N; i++)
            {
                mq[i].Enqueue(g[i * M + j]);
            }
        }

        long ans = 0;
        for (int j = B - 1; j < M; j++)
        {
            for (int i = 0; i < N; i++)
            {
                mq[i].Enqueue(g[i * M + j]);
            }

            var mq2 = new MinQueue();
            for (int i = 0; i < A - 1; i++)
            {
                mq2.Enqueue(mq[i].GetMin());
            }

            for (int i = A - 1; i < N; i++)
            {
                mq2.Enqueue(mq[i].GetMin());
                ans += mq2.GetMin();
                mq2.Dequeue();
            }

            for (int i = 0; i < N; i++)
            {
                mq[i].Dequeue();
            }
        }

        Console.WriteLine(ans);
    }

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

class MinStack
{
    private Stack<(int val, int min)> S;

    public MinStack()
    {
        S = new Stack<(int val, int min)>();
    }

    public int GetMin()
    {
        if (S.Count == 0) return int.MaxValue;
        return S.Peek().min;
    }

    public void Push(int val)
    {
        S.Push((val, Math.Min(val, GetMin())));
    }

    public int Pop()
    {
        return S.Pop().val;
    }

    public int Count
    {
        get { return S.Count; }
    }
}

class MinQueue
{
    public MinStack L, R;

    public MinQueue()
    {
        L = new MinStack();
        R = new MinStack();
    }

    public void Enqueue(int val)
    {
        R.Push(val);
    }

    public void Dequeue()
    {
        if (L.Count == 0)
        {
            while (R.Count > 0)
            {
                L.Push(R.Pop());
            }
        }

        L.Pop();
    }

    public int GetMin()
    {
        return Math.Min(L.GetMin(), R.GetMin());
    }
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


using System;
using CompLib.Collections.Generic;
using CompLib.Util;

public class Program
{
    private int N, M, A, B;
    private int G0, X, Y, Z;

    private long[] H;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();
        G0 = sc.NextInt();
        X = sc.NextInt();
        Y = sc.NextInt();
        Z = sc.NextInt();

        /*
         * N*Mグリッド
         * セル(i,j) は高さH[i,j]
         *
         * 画面には a*bの範囲が収まる
         *
         * 表示されてる範囲で最小のHの総和
         *
         *
         * g_i = (g_{i-1}*x+y) % Z
         * H[i,j] = g_{(i-1)*m+j-1}
         */

        var st = new SegmentTree[N];
        for (int i = 0; i < N; i++)
        {
            st[i] = new SegmentTree(M);
            for (int j = 0; j < M; j++)
            {
                if (i == 0 && j == 0) st[i][j] = G0;
                else
                {
                    st[i][j] = (int) ((long) st[i / M][i % M] * X + Y) % Z;
                }
            }
        }

        long ans = 0;
        for (int j = 0; j + B <= M; j++)
        {
            var st2 = new SegmentTree(A);
            for (int i = 0; i < A - 1; i++) st2[i] = st[i].Query(j, j + B);
            for (int i = A - 1; i < N; i++)
            {
                st2[i % A] = st[i].Query(j, j + B);
                ans += st2.Root();
            }
        }

        Console.WriteLine(ans);
    }

    int Conv(int i, int j)
    {
        return i * M + j;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Collections.Generic
{
    using System;

    public class SegmentTree
    {
        private readonly int N;
        private int[] _array;

        private const int _identity = int.MaxValue;

        public SegmentTree(int size)
        {
            N = 1;
            while (N < size) N *= 2;

            _array = new int[N * 2];
            for (int i = 1; i < N * 2; i++)
            {
                _array[i] = _identity;
            }
        }

        /// <summary>
        /// A[i]をnに更新 O(log N)
        /// </summary>
        /// <param name="i"></param>
        /// <param name="n"></param>
        public void Update(int i, int n)
        {
            i += N;
            _array[i] = n;
            while (i > 1)
            {
                i /= 2;
                _array[i] = System.Math.Min(_array[i * 2], _array[i * 2 + 1]);
            }
        }

        private int Query(int left, int right, int k, int l, int r)
        {
            if (r <= left || right <= l)
            {
                return _identity;
            }

            if (left <= l && r <= right)
            {
                return _array[k];
            }

            return Math.Min(Query(left, right, k * 2, l, (l + r) / 2),
                Query(left, right, k * 2 + 1, (l + r) / 2, r));
        }

        public int Root() => _array[1];

        /// <summary>
        /// A[left] op A[left+1] ... op A[right-1]を求める
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public int Query(int left, int right)
        {
            return Query(left, right, 1, 0, N);
        }

        public int this[int i]
        {
            set { Update(i, value); }
            get { return _array[i + N]; }
        }
    }
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Mathematics;

public class Program
{
    private long N, K, A, B;
    private long Min, Max;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();

        /*
         * n*k都市 1ごとに円周上
         *
         * n軒 kごとにファストフード店
         *
         * sからlkmごとの都市にsに戻るまで行く
         *
         * sから最寄りのファストフード店までa
         * s+lからb
         *
         * 通った都市の最大、最小
         */
        Min = int.MaxValue;
        Max = int.MinValue;
        F((A + B) % K);
        F((A - B) % K);
        F((-A + B) % K);
        F((-A - B) % K);
        /*
         * a,bも右
         * s % k = a
         * (s + l) % k = b
         *
         * (b - a)%k = l % k
         *
         *
         */

        Console.WriteLine($"{Min} {Max}");
    }

    void F(long l)
    {
        while (l <= 0) l += K;
        for (int i = 0; i < 500000; i++)
        {
            // Console.WriteLine(l);
            var gcd = MathEx.GCD(N * K, l);
            Min = Math.Min(Min, N * K / gcd);
            Max = Math.Max(Max, N * K / gcd);
            l += K;
        }
    }

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

// https://bitbucket.org/camypaper/complib
namespace CompLib.Mathematics
{
    using System;
    using System.Collections.Generic;

    #region GCD LCM

    /// <summary>
    /// 様々な数学的関数の静的メソッドを提供します．
    /// </summary>
    public static partial class MathEx
    {
        /// <summary>
        /// 2 つの整数の最大公約数を求めます．
        /// </summary>
        /// <param name="n">最初の値</param>
        /// <param name="m">2 番目の値</param>
        /// <returns>2 つの整数の最大公約数</returns>
        /// <remarks>ユークリッドの互除法に基づき最悪計算量 O(log N) で実行されます．</remarks>
        public static int GCD(int n, int m)
        {
            return (int) GCD((long) n, m);
        }

        /// <summary>
        /// 2 つの整数の最大公約数を求めます．
        /// </summary>
        /// <param name="n">最初の値</param>
        /// <param name="m">2 番目の値</param>
        /// <returns>2 つの整数の最大公約数</returns>
        /// <remarks>ユークリッドの互除法に基づき最悪計算量 O(log N) で実行されます．</remarks>
        public static long GCD(long n, long m)
        {
            n = Math.Abs(n);
            m = Math.Abs(m);
            while (n != 0)
            {
                m %= n;
                if (m == 0) return n;
                n %= m;
            }

            return m;
        }

        /// <summary>
        /// 2 つの整数の最小公倍数を求めます．
        /// </summary>
        /// <param name="n">最初の値</param>
        /// <param name="m">2 番目の値</param>
        /// <returns>2 つの整数の最小公倍数</returns>
        /// <remarks>最悪計算量 O(log N) で実行されます．</remarks>
        public static long LCM(long n, long m)
        {
            return (n / GCD(n, m)) * m;
        }
    }

    #endregion

    #region PrimeSieve

    public static partial class MathEx
    {
        /// <summary>
        /// ある値までに素数表を構築します．
        /// </summary>
        /// <param name="max">最大の値</param>
        /// <param name="primes">素数のみを入れた数列が返される</param>
        /// <returns>0 から max までの素数表</returns>
        /// <remarks>エラトステネスの篩に基づき，最悪計算量 O(N loglog N) で実行されます．</remarks>
        public static bool[] Sieve(int max, List<int> primes = null)
        {
            var isPrime = new bool[max + 1];
            for (int i = 2; i < isPrime.Length; i++) isPrime[i] = true;
            for (int i = 2; i * i <= max; i++)
                if (!isPrime[i]) continue;
                else
                    for (int j = i * i; j <= max; j += i)
                        isPrime[j] = false;
            if (primes != null)
                for (int i = 0; i <= max; i++)
                    if (isPrime[i])
                        primes.Add(i);

            return isPrime;
        }
    }

    #endregion
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long K = long.Parse(str[1]);
		string[] str2 = Console.ReadLine().Split();
		long A = long.Parse(str2[0]);
		long B = long.Parse(str2[1]);
		long min = 999999999;
		long max = 0;
		for(var i=0;i<N;i++){
			long a1 = Math.Abs(i*K+B - A);
			if(a1==0){
				min = 1;
			} else {
				min = Math.Min(min,N*K/Gcd(a1,N*K));
			}
			max = Math.Max(max,N*K/Gcd(a1,N*K));
			long a2 = Math.Abs(i*K+B + A);
			min = Math.Min(min,N*K/Gcd(a2,N*K));
			max = Math.Max(max,N*K/Gcd(a2,N*K));
		}
		Console.WriteLine(min+" "+max);
	}
	public static long Lcm(long a, long b) {
        return a * b / Gcd(a, b);
    }

	public static long Gcd(long a, long b) {
		if (a < b)
			return Gcd(b, a);
		while (b != 0) {
			var r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
}


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

class Solver
{
    Scanner sc = new Scanner();
    //

    public void Solve()
    {
        long n, k, a, b;
        sc.Make(out n, out k, out a, out b);
        long min = long.MaxValue, max = long.MinValue;
        for(var i = 0; i <= n; i++)
        {
            long l = i * k + b, r = i * k + k - b;
            if (l == a) goto S;
            var p = LCM(n * k, Abs(l - a)) / Abs(l - a);
            chmin(ref min, p);chmax(ref max, p);
        S:;
            if (r == a) continue;
            var q = LCM(n * k, Abs(r - a)) / Abs(r - a);
            chmax(ref max, q);chmin(ref min, q);
        }
        WriteLine($"{min} {max}");
    }
    #region GCD
    public static int LCM(int num1, int num2)
        => num1 / GCD(num1, num2) * num2;

    public static long LCM(long num1, long num2)
        => num1 / GCD(num1, num2) * num2;

    public static int GCD(int num1, int num2)
        => num1 < num2 ? GCD(num2, num1) :
           num2 > 0 ? GCD(num2, num1 % num2) : num1;

    public static long GCD(long num1, long num2)
        => num1 < num2 ? GCD(num2, num1) :
           num2 > 0 ? GCD(num2, num1 % num2) : num1;
    #endregion
}

#region Template
public class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve();
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

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

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

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

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

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


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Mathematics;

public class Program
{
    private long N, K, A, B;
    private long Min, Max;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();

        /*
         * n*k都市 1ごとに円周上
         *
         * n軒 kごとにファストフード店
         *
         * sからlkmごとの都市にsに戻るまで行く
         *
         * sから最寄りのファストフード店までa
         * s+lからb
         *
         * 通った都市の最大、最小
         */
        Min = int.MaxValue;
        Max = int.MinValue;
        F((A + B) % K);
        F((A - B) % K);
        F((B - A) % K);
        F((-A - B) % K);
        /*
         * a,bも右
         * s % k = a
         * (s + l) % k = b
         *
         * (b - a)%k = l % k
         *
         *
         */

        Console.WriteLine($"{Min} {Max}");
    }

    void F(long l)
    {
        var hs = new HashSet<long>();
        while (l <= 0) l += K;
        while (true)
        {
            // Console.WriteLine(l);
            var gcd = MathEx.GCD(N * K, l);
            if (!hs.Add(gcd)) break;
            Min = Math.Min(Min, N * K / gcd);
            Max = Math.Max(Max, N * K / gcd);
            l += K;
        }
    }

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

// https://bitbucket.org/camypaper/complib
namespace CompLib.Mathematics
{
    using System;
    using System.Collections.Generic;

    #region GCD LCM

    /// <summary>
    /// 様々な数学的関数の静的メソッドを提供します．
    /// </summary>
    public static partial class MathEx
    {
        /// <summary>
        /// 2 つの整数の最大公約数を求めます．
        /// </summary>
        /// <param name="n">最初の値</param>
        /// <param name="m">2 番目の値</param>
        /// <returns>2 つの整数の最大公約数</returns>
        /// <remarks>ユークリッドの互除法に基づき最悪計算量 O(log N) で実行されます．</remarks>
        public static int GCD(int n, int m)
        {
            return (int) GCD((long) n, m);
        }

        /// <summary>
        /// 2 つの整数の最大公約数を求めます．
        /// </summary>
        /// <param name="n">最初の値</param>
        /// <param name="m">2 番目の値</param>
        /// <returns>2 つの整数の最大公約数</returns>
        /// <remarks>ユークリッドの互除法に基づき最悪計算量 O(log N) で実行されます．</remarks>
        public static long GCD(long n, long m)
        {
            n = Math.Abs(n);
            m = Math.Abs(m);
            while (n != 0)
            {
                m %= n;
                if (m == 0) return n;
                n %= m;
            }

            return m;
        }

        /// <summary>
        /// 2 つの整数の最小公倍数を求めます．
        /// </summary>
        /// <param name="n">最初の値</param>
        /// <param name="m">2 番目の値</param>
        /// <returns>2 つの整数の最小公倍数</returns>
        /// <remarks>最悪計算量 O(log N) で実行されます．</remarks>
        public static long LCM(long n, long m)
        {
            return (n / GCD(n, m)) * m;
        }
    }

    #endregion

    #region PrimeSieve

    public static partial class MathEx
    {
        /// <summary>
        /// ある値までに素数表を構築します．
        /// </summary>
        /// <param name="max">最大の値</param>
        /// <param name="primes">素数のみを入れた数列が返される</param>
        /// <returns>0 から max までの素数表</returns>
        /// <remarks>エラトステネスの篩に基づき，最悪計算量 O(N loglog N) で実行されます．</remarks>
        public static bool[] Sieve(int max, List<int> primes = null)
        {
            var isPrime = new bool[max + 1];
            for (int i = 2; i < isPrime.Length; i++) isPrime[i] = true;
            for (int i = 2; i * i <= max; i++)
                if (!isPrime[i]) continue;
                else
                    for (int j = i * i; j <= max; j += i)
                        isPrime[j] = false;
            if (primes != null)
                for (int i = 0; i <= max; i++)
                    if (isPrime[i])
                        primes.Add(i);

            return isPrime;
        }
    }

    #endregion
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


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

public class Program
{
    private long N, K, A, B;
    private long Min, Max;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();

        /*
         * n*k都市 1ごとに円周上
         *
         * n軒 kごとにファストフード店
         *
         * sからlkmごとの都市にsに戻るまで行く
         *
         * sから最寄りのファストフード店までa
         * s+lからb
         *
         * 通った都市の最大、最小
         */
        Min = int.MaxValue;
        Max = int.MinValue;
        F((A + B) % K);
        F((A - B) % K);
        F((B - A) % K);
        F((-A - B) % K);
        /*
         * a,bも右
         * s % k = a
         * (s + l) % k = b
         *
         * (b - a)%k = l % k
         *
         *
         */

        Console.WriteLine($"{Min} {Max}");
    }

    void F(long l)
    {
        if (l <= 0) l += K;

        for (int i = 0; i < N; i++)
        {
            // Console.WriteLine(l);
            var gcd = MathEx.GCD(N * K, l);
            Min = Math.Min(Min, N * K / gcd);
            Max = Math.Max(Max, N * K / gcd);
            l += K;
        }
    }

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

// https://bitbucket.org/camypaper/complib
namespace CompLib.Mathematics
{
    using System;
    using System.Collections.Generic;

    #region GCD LCM

    /// <summary>
    /// 様々な数学的関数の静的メソッドを提供します．
    /// </summary>
    public static partial class MathEx
    {
        /// <summary>
        /// 2 つの整数の最大公約数を求めます．
        /// </summary>
        /// <param name="n">最初の値</param>
        /// <param name="m">2 番目の値</param>
        /// <returns>2 つの整数の最大公約数</returns>
        /// <remarks>ユークリッドの互除法に基づき最悪計算量 O(log N) で実行されます．</remarks>
        public static int GCD(int n, int m)
        {
            return (int) GCD((long) n, m);
        }

        /// <summary>
        /// 2 つの整数の最大公約数を求めます．
        /// </summary>
        /// <param name="n">最初の値</param>
        /// <param name="m">2 番目の値</param>
        /// <returns>2 つの整数の最大公約数</returns>
        /// <remarks>ユークリッドの互除法に基づき最悪計算量 O(log N) で実行されます．</remarks>
        public static long GCD(long n, long m)
        {
            n = Math.Abs(n);
            m = Math.Abs(m);
            while (n != 0)
            {
                m %= n;
                if (m == 0) return n;
                n %= m;
            }

            return m;
        }

        /// <summary>
        /// 2 つの整数の最小公倍数を求めます．
        /// </summary>
        /// <param name="n">最初の値</param>
        /// <param name="m">2 番目の値</param>
        /// <returns>2 つの整数の最小公倍数</returns>
        /// <remarks>最悪計算量 O(log N) で実行されます．</remarks>
        public static long LCM(long n, long m)
        {
            return (n / GCD(n, m)) * m;
        }
    }

    #endregion

    #region PrimeSieve

    public static partial class MathEx
    {
        /// <summary>
        /// ある値までに素数表を構築します．
        /// </summary>
        /// <param name="max">最大の値</param>
        /// <param name="primes">素数のみを入れた数列が返される</param>
        /// <returns>0 から max までの素数表</returns>
        /// <remarks>エラトステネスの篩に基づき，最悪計算量 O(N loglog N) で実行されます．</remarks>
        public static bool[] Sieve(int max, List<int> primes = null)
        {
            var isPrime = new bool[max + 1];
            for (int i = 2; i < isPrime.Length; i++) isPrime[i] = true;
            for (int i = 2; i * i <= max; i++)
                if (!isPrime[i]) continue;
                else
                    for (int j = i * i; j <= max; j += i)
                        isPrime[j] = false;
            if (primes != null)
                for (int i = 0; i <= max; i++)
                    if (isPrime[i])
                        primes.Add(i);

            return isPrime;
        }
    }

    #endregion
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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