#region Using Statements
using GenericArithmetic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

#endregion
namespace csConsoleforStudy
{
 using System.Collections.Generic;
 using System.Globalization;

 class Program
 {
  static readonly Encoding TargetEcoding = Encoding.Unicode;
  static void Main(string[] args)
  {
   OpenStream();
   Solver s = new Solver();
   s.Solve();
   CloseStream();
  }

  static void OpenStream()
  {
  }

  static void CloseStream()
  {
  }

  static void CheckMemory()
  {
  }
 }

 class Solver
 {
  public static readonly Encoding TargetEncoding = Encoding.Unicode;
  const int SIZE = 5005;
  private const double AbsoluteError = 1e-10;
  private const double RelativeError = 1e-8;
  static int mod = 1000000007;
  public void Solve()
  {
   string s1 = rs();
   string s2 = rs();
   int target = 0;
   int pos = 0;
   int que = 0;
   double result = 0f;
   for (int i = 0; i < s1.Length; i++)
   {
    if (s1[i] == '+')
     target++;
    else
     target--;
   }

   for (int i = 0; i < s2.Length; i++)
   {
    if (s2[i] == '+')
     pos++;
    else if (s2[i] == '-')
     pos--;
    else
    {
     que++;
    }
   }

   if (que % 2 == 0)
   {
    if ((target - pos) % 2 == 0)
    {
     int d = target - pos;
     d = Math.Abs(d);
     int plus = d;
     int minus = 0;
     for (int i = 0;; i++)
     {
      if (plus + minus == que)
       break;
      plus++;
      minus++;
     }

     result = (double)C(que, plus) / Math.Pow(2, que);
    }
    else
     result = 0f;
   }
   else
   {
    if ((target - pos) % 2 == 1)
    {
     int d = target - pos;
     d = Math.Abs(d);
     int plus = d;
     int minus = 0;
     for (int i = 0;; i++)
     {
      if (plus + minus == que)
       break;
      plus++;
      minus++;
     }

     result = (double)C(que, plus) / Math.Pow(2, que);
    }
    else
     result = 0f;
   }

   string ans = result.ToString("F10", CultureInfo.InvariantCulture);
   Console.Write(ans);
  }

#region SolverUtils
  private static List<int> factorial = new List<int>(new int[]{1});
  private static int NextInt()
  {
   int c;
   int res = 0;
   do
   {
    c = Console.Read();
    if (c == -1)
     return res;
   }
   while (c < '0' || c > '9');
   res = c - '0';
   while (true)
   {
    c = Console.Read();
    if (c < '0' || c > '9')
     return res;
    res *= 10;
    res += c - '0';
   }
  }

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

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

  static uint rui()
  {
   return uint.Parse(Console.ReadLine());
  }

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

  static ulong rul()
  {
   return ulong.Parse(Console.ReadLine());
  }

  static double rd()
  {
   return double.Parse(Console.ReadLine());
  }

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

  static int[] ria()
  {
   return Array.ConvertAll(Console.ReadLine().Split(' '), e => int.Parse(e));
  }

  static uint[] ruia()
  {
   return Array.ConvertAll(Console.ReadLine().Split(' '), e => uint.Parse(e));
  }

  static long[] rla()
  {
   return Array.ConvertAll(Console.ReadLine().Split(' '), e => long.Parse(e));
  }

  static ulong[] rula()
  {
   return Array.ConvertAll(Console.ReadLine().Split(' '), e => ulong.Parse(e));
  }

  static double[] rda()
  {
   return Array.ConvertAll(Console.ReadLine().Split(' '), e => double.Parse(e));
  }

  static void ReadLineAndAssign(string type, params object[] p)
  {
   dynamic input;
   if (type.StartsWith("i"))
    input = ria();
   else if (type.StartsWith("l"))
    input = rla();
   else if (type.StartsWith("d"))
    input = rda();
   else
    throw new ArgumentException("no match " + type.ToString());
   for (int i = 0; i < p.Length; i++)
   {
    p[i] = input[i];
   }
  }

  static void SwapIfGreater<T>(ref T lhs, ref T rhs)where T : IComparable<T>
  {
   T temp;
   if (lhs.CompareTo(rhs) > 0)
   {
    temp = lhs;
    lhs = rhs;
    rhs = temp;
   }
  }

  static bool DoubleEqual(double a, double b)
  {
   double diff = Math.Abs(a - b);
   if (diff < AbsoluteError)
    return true;
   return diff <= RelativeError * Math.Max(Math.Abs(a), Math.Abs(b));
  }

  static dynamic abs(dynamic num)
  {
   return Math.Abs(num);
  }

  static dynamic max(dynamic a, dynamic b)
  {
   return Math.Max(a, b);
  }

  static void For(int start, int end, Action method)
  {
   for (int i = start; i < end; i++)
   {
    method.Invoke();
   }
  }

  static void For(int start, int end, Action<int> method, int i)
  {
   for (i = start; i < end; i++)
   {
    method.DynamicInvoke(i);
   }
  }

  static int C(int n, int k)
  {
   return P(n, k) / Factorial(k);
  }

  static int P(int n, int r)
  {
   return Factorial(n) / Factorial(n - r);
  }

  static int Factorial(int n)
  {
   if (factorial.Count <= n)
    factorial.Add(Factorial(n - 1) * n);
   return factorial[n];
  }

  static int powmod(int a, int b)
  {
   if (b == 0)
    return 1;
   if (b == 1)
    return a;
   int i = powmod(a, b / 2);
   i *= i;
   i %= mod;
   if (b % 2 == 0)
    return i;
   else
    return ((i * a) % mod);
  }
#endregion
 }
#region SolverUtils
#endregion
#region Data Structure
#endregion
#region Algorithm
#endregion
#region Library Method/Fields
#region Members for Internal Support
#endregion Members for Internal Support
#region Public Properties
#endregion Public Properties
#region Public Instance Methods
#endregion Public Instance Methods
#region Constructors
#endregion Constructors
#region Public Static Methods
#endregion Public Static Methods
#region Operator Overloads
#endregion Operator Overloads
#region explicit conversions from BigRational
#endregion explicit conversions from BigRational
#region implicit conversions to BigRational
#endregion implicit conversions to BigRational
#region serialization
#endregion serialization
#region instance helper methods
#endregion instance helper methods
#region static helper methods
#endregion static helper methods
#region Exceptions
#endregion
#endregion
}

#region Libraries
namespace GenericArithmetic
{
 public class Vector<T>
 {
  public static readonly ICalculator<T> Calculator = Number<T>.Calculator;
  public T X
  {
   get;
   set;
  }

  public T Y
  {
   get;
   set;
  }

  public Vector(T x, T y)
  {
   X = x;
   Y = y;
  }

  public override bool Equals(object obj)
  {
   return base.Equals(obj);
  }

  public override int GetHashCode()
  {
   return base.GetHashCode();
  }

  public static bool operator ==(Vector<T> a, Vector<T> b)
  {
   return EqualityComparer<T>.Default.Equals(a.X, b.X) && EqualityComparer<T>.Default.Equals(a.Y, b.Y);
  }

  public static bool operator !=(Vector<T> a, Vector<T> b)
  {
   return !(EqualityComparer<T>.Default.Equals(a.X, b.X) && EqualityComparer<T>.Default.Equals(a.Y, b.Y));
  }

  public static Vector<T> operator !(Vector<T> a)
  {
   return new Vector<T>(Calculator.Difference(new Number<T>(default (T)), a.X), Calculator.Difference(new Number<T>(default (T)), a.Y));
  }

  public static Vector<T> operator +(Vector<T> a, Vector<T> b)
  {
   return new Vector<T>(Calculator.Sum(a.X, b.X), Calculator.Sum(a.Y, b.Y));
  }

  public static Vector<T> operator -(Vector<T> a, Vector<T> b)
  {
   return new Vector<T>(Calculator.Difference(a.X, b.X), Calculator.Difference(a.Y, b.Y));
  }
 }

 public class Matrix<T>
 {
  public static readonly ICalculator<T> Calculator = Number<T>.Calculator;
  public int W
  {
   get;
   set;
  }

  public int H
  {
   get;
   set;
  }

  public int rows
  {
   get
   {
    return H;
   }

   set
   {
    H = value;
   }
  }

  public int cols
  {
   get
   {
    return W;
   }

   set
   {
    W = value;
   }
  }

  public T[, ] Map
  {
   get;
   set;
  }

  public T this[int x, int y]
  {
   get
   {
    return Map[x, y];
   }

   set
   {
    Map[x, y] = value;
   }
  }

  public Matrix(T[, ] map)
  {
   Map = map;
   W = map.GetLength(0);
   H = map.GetLength(1);
  }

  public Matrix(int w, int h, T defaultValue = default (T))
  {
   W = w;
   H = h;
   Map = new T[W, H];
  }

  public override bool Equals(object obj)
  {
   if (obj is Matrix<T>)
   {
    return this == (Matrix<T>)obj;
   }

   return base.Equals(obj);
  }

  public override int GetHashCode()
  {
   return base.GetHashCode();
  }

  public static bool operator ==(Matrix<T> a, Matrix<T> b)
  {
   bool ret = true;
   if (a.Map != b.Map)
    ret = false;
   else if (a.W != b.W)
    ret = false;
   else if (a.H != b.H)
    ret = false;
   return ret;
  }

  public static bool operator !=(Matrix<T> a, Matrix<T> b)
  {
   bool ret = true;
   if (a.Map != b.Map)
    ret = false;
   else if (a.W != b.W)
    ret = false;
   else if (a.H != b.H)
    ret = false;
   return !ret;
  }

  public static Matrix<T> operator +(Matrix<T> a, Matrix<T> b)
  {
   if (a.W != b.W)
    return null;
   else if (a.H != b.H)
    return null;
   else
   {
    Matrix<T> ret = new Matrix<T>(a.W, a.H);
    for (int i = 0; i < a.W; i++)
    {
     for (int j = 0; j < a.H; j++)
     {
      ret[i, j] = Calculator.Sum(a[i, j], b[i, j]);
     }
    }

    return ret;
   }
  }

  public static Matrix<T> operator -(Matrix<T> a, Matrix<T> b)
  {
   if (a.W != b.W)
    return null;
   else if (a.H != b.H)
    return null;
   else
   {
    Matrix<T> ret = new Matrix<T>(a.W, a.H);
    for (int i = 0; i < a.W; i++)
    {
     for (int j = 0; j < a.H; j++)
     {
      ret[i, j] = Calculator.Difference(a[i, j], b[i, j]);
     }
    }

    return ret;
   }
  }

  public static Matrix<T> operator *(Matrix<T> a, Matrix<T> b)
  {
   if (a.cols != b.rows)
    throw new FormatException("Cannot multiply : a.W = " + a.W.ToString() + " with b.H = " + b.H.ToString());
   else
   {
    Matrix<T> R = new Matrix<T>(a.rows, b.cols);
    for (int i = 0; i < R.rows; i++)
     for (int j = 0; j < R.cols; j++)
      for (int k = 0; k < a.cols; k++)
      {
       R[i, j] = Calculator.Sum(R[i, j], Calculator.Multiply(a[i, k], b[k, j]));
      }

    return R;
   }
  }
 }

 public static class Calculator
 {
  public static T Sum<T>(T a, T b)
  {
   return Number<T>.Sum(a, b);
  }
 }

 public interface ICalculator<T>
 {
  T Sum(T a, T b);
  T Difference(T a, T b);
  int Compare(T a, T b);
  T Multiply(T a, T b);
  T Divide(T a, T b);
  T Divide(T a, int b);
 }

 struct Int32Calculator : ICalculator<Int32>
 {
  public Int32 Sum(Int32 a, Int32 b)
  {
   return a + b;
  }

  public Int32 Difference(Int32 a, Int32 b)
  {
   return a - b;
  }

  public int Compare(Int32 a, Int32 b)
  {
   return Difference(a, b);
  }

  public int Multiply(Int32 a, Int32 b)
  {
   return a * b;
  }

  public int Divide(Int32 a, Int32 b)
  {
   return a / b;
  }
 }

 struct Int64Calculator : ICalculator<Int64>
 {
  public Int64 Sum(Int64 a, Int64 b)
  {
   return a + b;
  }

  public Int64 Difference(Int64 a, Int64 b)
  {
   return a - b;
  }

  public int Compare(Int64 a, Int64 b)
  {
   if (a > b)
   {
    return 1;
   }
   else if (a < b)
   {
    return -1;
   }
   else
   {
    return 0;
   }
  }

  public Int64 Multiply(Int64 a, Int64 b)
  {
   return a * b;
  }

  public Int64 Divide(Int64 a, Int64 b)
  {
   return a / b;
  }

  public Int64 Divide(Int64 a, int b)
  {
   return a / b;
  }
 }

 struct SingleCalculator : ICalculator<Single>
 {
  public Single Sum(Single a, Single b)
  {
   return a + b;
  }

  public Single Difference(Single a, Single b)
  {
   return a - b;
  }

  public int Compare(Single a, Single b)
  {
   if (a > b)
   {
    return 1;
   }
   else if (a < b)
   {
    return -1;
   }
   else
   {
    return 0;
   }
  }

  public Single Multiply(Single a, Single b)
  {
   return a * b;
  }

  public Single Divide(Single a, Single b)
  {
   return a / b;
  }

  public Single Divide(Single a, int b)
  {
   return a / b;
  }
 }

 struct DoubleCalculator : ICalculator<double>
 {
  public double Sum(double a, double b)
  {
   return a + b;
  }

  public double Difference(double a, double b)
  {
   return a - b;
  }

  public int Compare(double a, double b)
  {
   if (a > b)
   {
    return 1;
   }
   else if (a < b)
   {
    return -1;
   }
   else
   {
    return 0;
   }
  }

  public double Multiply(double a, double b)
  {
   return a * b;
  }

  public Double Divide(Double a, Double b)
  {
   return a / b;
  }

  public Double Divide(Double a, int b)
  {
   return a / b;
  }
 }

 struct StringCalculator : ICalculator<string>
 {
  public string Sum(string a, string b)
  {
   return a + b;
  }

  public string Difference(string a, string b)
  {
   if (b.Length < a.Length)
   {
    return a.Substring(0, b.Length);
   }
   else
   {
    return "";
   }
  }

  public int Compare(string a, string b)
  {
   return a.CompareTo(b);
  }

  public string Multiply(string a, string b)
  {
   if (a.Length == 1 && b.Length == 1)
   {
    return ((char)(((byte)a[0] * (byte)b[0]) % 256)) + "";
   }

   int bigLength = Math.Max(a.Length, b.Length);
   while (a.Length < bigLength)
   {
    a = " " + a;
   }

   while (b.Length < bigLength)
   {
    b = " " + b;
   }

   string result = "";
   for (int i = 0; i < bigLength; i++)
   {
    Number<string> numA = a[i] + "";
    Number<string> numB = b[i] + "";
    result += numA * numB;
   }

   return result;
  }

  public String Divide(String a, String b)
  {
   return String.Format("{0} / {1}", a, b);
  }

  public String Divide(String a, int b)
  {
   return String.Format("{0} / {1}", a, b);
  }
 }

 public class Number<T>
 {
  private T value;
  public Number(T value)
  {
   this.value = value;
   Type calculatorType = GetCalculatorType();
   fCalculator = Activator.CreateInstance(calculatorType) as ICalculator<T>;
  }

  public static Type GetCalculatorType()
  {
   Type tType = typeof (T);
   Type calculatorType = null;
   if (tType == typeof (Int32))
   {
    calculatorType = typeof (Int32Calculator);
   }
   else if (tType == typeof (Int64))
   {
    calculatorType = typeof (Int64Calculator);
   }
   else if (tType == typeof (Double))
   {
    calculatorType = typeof (DoubleCalculator);
   }
   else if (tType == typeof (string))
   {
    calculatorType = typeof (StringCalculator);
   }
   else
   {
    throw new InvalidCastException(String.Format("Unsupported Type- Type {0} does not have a partner implementation of interface ICalculator<T> and cannot be used in generic arithmetic using type Number<T>", tType.Name));
   }

   return calculatorType;
  }

  private static ICalculator<T> fCalculator = null;
  public static ICalculator<T> Calculator
  {
   get
   {
    if (fCalculator == null)
    {
     MakeCalculator();
    }

    return fCalculator;
   }
  }

  public static void MakeCalculator()
  {
   Type calculatorType = GetCalculatorType();
   fCalculator = Activator.CreateInstance(calculatorType) as ICalculator<T>;
  }

#region operation methods
  public static T Sum(T a, T b)
  {
   return Calculator.Sum(a, b);
  }

  public static T Difference(T a, T b)
  {
   return Calculator.Difference(a, b);
  }

  public static int Compare(T a, T b)
  {
   return Calculator.Compare(a, b);
  }

  public static T Multiply(T a, T b)
  {
   return Calculator.Multiply(a, b);
  }

  public static T Divide(T a, T b)
  {
   return Calculator.Divide(a, b);
  }

  public static T Divide(T a, int b)
  {
   return Calculator.Divide(a, b);
  }

#endregion
#region Operators
  public static implicit operator Number<T>(T a)
  {
   return new Number<T>(a);
  }

  public static implicit operator T(Number<T> a)
  {
   return a.value;
  }

  public static Number<T> operator +(Number<T> a, Number<T> b)
  {
   return Calculator.Sum(a.value, b.value);
  }

  public static Number<T> operator -(Number<T> a, Number<T> b)
  {
   return Calculator.Difference(a, b);
  }

  public static bool operator>(Number<T> a, Number<T> b)
  {
   return Calculator.Compare(a, b) > 0;
  }

  public static bool operator <(Number<T> a, Number<T> b)
  {
   return Calculator.Compare(a, b) < 0;
  }

  public static Number<T> operator *(Number<T> a, Number<T> b)
  {
   return Calculator.Multiply(a, b);
  }

  public static Number<T> operator /(Number<T> a, Number<T> b)
  {
   return Calculator.Divide(a, b);
  }

  public static Number<T> operator /(Number<T> a, int b)
  {
   return Calculator.Divide(a, b);
  }
#endregion
 }
}
#region DataStructures
#region IComparable implementation
#endregion
#region Model
#endregion
#region Constructors
#endregion
#region Internal
#region IEqualityComparer implementation
#endregion
#endregion
#region IGraph implementation
#endregion
#region Clique invariants
#endregion
#region Clique methods
#endregion
#region IEquatable implementation
#endregion
#endregion
#region Algorithms
#endregion
#endregion


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[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 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();
    }
}


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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			string input2 = Console.ReadLine();
			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] { ' ', '}', '{' , ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
			var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

			int n = inputs1[0];
			int k = inputs1[1];

			if (n == 1)
			{
				Console.WriteLine(inputs2[0] > k ? 0 : 1);
				return;
			}

			int startIndex = 0, endIndex = n - 1;
			int min = Math.Min(inputs2[startIndex], inputs2[endIndex]);
			int count = 0;
			while (min <= k)
			{
				if (min == inputs2[startIndex])
				{
					startIndex++;
				}
				else
				{
					endIndex--;
				}

				count++;
				min = Math.Min(inputs2[startIndex], inputs2[endIndex]);
			}

			Console.WriteLine(count);
		}

		private static long NumbersSum(long a)
		{
			long copyA = a, sum = 0;
			while (copyA > 0)
			{
				sum += copyA % 10;
				copyA /= 10;
			}

			return sum;
		}

		private static long GCD(long a, long b)
		{
			long max = Math.Max(a, b);
			long min = Math.Min(a, b);

			if (min == 0)
			{
				return max;
			}
			a = min;
			b = max % min;
			return GCD(a, b);
		}

		private static long LCM(long a, long b)
		{
			return Math.Abs(a * b) / GCD(a, b);
		}

		static long Factorial(long a)
		{
			return a > 1 ? a * Factorial(a - 1) : 1;
		}
	}
}


using System;

namespace helloworld
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split(' ');
            var line2 = Console.ReadLine().Split(' ');

            var n = int.Parse(line1[0]);
            var k = int.Parse(line1[1]);
            int count = 0;
            int i=0;
            int j = n-1;

            while(int.Parse(line2[i]) <= k && i!=j)
            {
                count++;
                i++;
            }
            while(int.Parse(line2[j]) <= k && i<=j)
            {
                count++;
                j--;
            }
            Console.WriteLine(count);
        }
    }
}


using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace CodeForces
{
    class Program
    {
        static int NthRootFloor(double A, int N)
        {
            return (int)Math.Floor(Math.Pow(A, 1.0 / N));
        }

        static void generate(int limit, int k)
        {
            var source = "codeforces".ToCharArray();
            var output = new StringBuilder(k * source.Length);
            for(int i = 0; i < source.Length; ++i)
            {
                var addOne = i < limit ? 1 : 0;
                output.Append(new string(source[i], k + addOne));
            }
            Console.WriteLine(output);
        }

        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine().Trim());
            var kInt = NthRootFloor(k, 10);
            if (kInt < 1)
            {
                kInt = 1;
            }
            int [] data = new int[10];
            for (int i = 0; i < data.Length; ++i)
            {
                data[i] = kInt;
            }
            long tmp = 1;
            for (int i = 0; i < data.Length; ++i)
            {
                tmp = tmp * kInt;
            }
            if (tmp >= k)
            {
                generate(0, kInt);
                return;
            }
            for (int i = 0; i < data.Length; ++i)
            {
                tmp /= kInt;
                tmp *= (kInt + 1);
                if (tmp >= k)
                {
                    generate(i + 1, kInt);
                    return;
                }
            }
        }
    }
}


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

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

            //Codeforces Subsequences

            long k = long.Parse(Console.ReadLine());

            long x = (long)Math.Pow(1.0 * k, 0.1), y;

            if (Math.Pow(1.0 * k, 0.1) == (long)Math.Pow(1.0 * k, 0.1))
            {

                y = x;

            }
            else
            {

                y = x + 1;

            }

            char[] ch = { 'C', 'O', 'd', 'E', 'f', 'o', 'r', 'c', 'e', 's' };

            int fy = 0, fx = 10;

            Dictionary<char, long> f = new Dictionary<char, long>();

            for (int i = 0; i < 10; i++)
            {

                f[ch[i]] = x;

            }

            int py = (int)Math.Pow(1.0 * y, 1.0 * fy);
            int px = (int)Math.Pow(1.0 * x, 1.0 * fx);

            int c = 0;

            while (py * px < k)
            {

                f[ch[c]] = y;

                c++;

                fy++;
                fx--;

                py = (int)Math.Pow(1.0 * y, 1.0 * fy);
                px = (int)Math.Pow(1.0 * x, 1.0 * fx);

            }

            for (long i = 0; i < 10; i++)
            {

                for (long j = 1; j <= f[ch[i]]; j++)
                {

                    Console.Write(char.ToLower(ch[i]));

                }

            }

        }
    }
}


using System;

class Program
{
	static void Main()
	{
		int stone = int.Parse();
		string colors = Console.ReadLine();
		int counter = 0;
		for(int i = 1; i < stone; i++)
		{
			if(colors[i-1] != colors[i])
			{
				continue;
			}
			else
			{
				counter++;
			}
		}
		Console.WriteLine(counter);
	}
}


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

namespace B.Code_obfuscation
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            char[] alphabets = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
            int flag = 0;
            char x=' ';
            if (s[0] != 'a')
            {
                Console.WriteLine("NO");
            }
            else
            {
                flag = 1;
                for (int i = 1; i < s.Length; i++)
                {
                    flag = 0;
                    for (int j = 1; j < alphabets.Length; j++)
                    {
                        if (s[i] == alphabets[i])
                        {
                            x = alphabets[i - 1];
                            break;
                        }
                    }
                    for (int k = 0; k < i; k++)
                    {
                        if (s[k] == x || s[k] == s[0])
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 1)
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                if (flag == 1)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Debug = System.Diagnostics.Debug;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
namespace Solver
{
    public class Solver
    {
        public void Solve()
        {
            var H = sc.Long();
            var W = sc.Long();
            var k = sc.Long();
            long max = -1;
            for (long i = 1; i * i <= 2 * H; i++)
            {
                var h = H / i;
                var u = i - 1;
                var rem = k - u;
                var w = W / (rem + 1);
                if (h * w > 0)
                    max = Math.Max(h * w, max);

            }
            IO.Printer.Out.WriteLine(max);

        }

        internal IO.StreamScanner sc;
        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; }

    }
    #region Main and Settings
    static class Program
    {
        static void Main(string[] arg)
        {
#if DEBUG
            var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
            Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            Debug.AutoFlush = false;
            var sw = new Watch(); sw.Start();
            IO.Printer.Out.AutoFlush = true;
            try
            {
#endif

                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                solver.Solve();
                IO.Printer.Out.Flush();
#if DEBUG
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
            finally
            {
                sw.Stop();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds);
                Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}

#region IO Helper
namespace Solver.IO
{
    public class Printer : System.IO.StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
#if DEBUG
            Error = new Printer(Console.OpenStandardError()) { AutoFlush = true };
#else
            Error = new Printer(System.IO.Stream.Null) { AutoFlush = false };
#endif
        }
        public static Printer Out { get; set; }
        public static Printer Error { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(System.IO.Stream stream) { iStream = stream; }
        private readonly System.IO.Stream iStream;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private bool eof = false;
        public bool IsEndOfStream { get { return eof; } }
        const byte lb = 33, ub = 126, el = 10, cr = 13;
        public byte read()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b); return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }
        public string Scan()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            var enc = System.Text.UTF8Encoding.Default;
            do
            {
                for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;
                if (ptr < len) break;
                ptr = 0;
                if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return ""; }
            } while (true);
            do
            {
                var f = ptr;
                for (; ptr < len; ptr++)
                    if (buf[ptr] < lb || ub < buf[ptr])
                    //if (buf[ptr] == cr || buf[ptr] == el)
                    {
                        string s;
                        if (sb == null) s = enc.GetString(buf, f, ptr - f);
                        else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }
                        ptr++; return s;
                    }
                if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));
                else sb.Append(enc.GetChars(buf, f, len - f));
                ptr = 0;

            }
            while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true; return (sb != null) ? sb.ToString() : "";
        }
        public long Long()
        {
            long ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public int Integer()
        {
            int ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }
        public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; }
        public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }
        public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++)a[i] = Long(); return a; }
        public void Flush() { iStream.Flush(); }
    }
}
#endregion
#region Extension
namespace Solver.Ex
{
    static public partial class EnumerableEx
    {
        static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
        static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }

    }
}
#endregion


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

namespace CodeForcesTrainingCSharp
{
    class Program
    {
        static int Main(string[] args)
        {
            Process();
            Console.ReadLine();
            return 0;
        }
        static void Process()
        {
            long[] nmk = Array.ConvertAll<string, long>(Console.ReadLine().Split(' '), r => long.Parse(r));
            long n = nmk[0]>nmk[1]?nmk[1]:nmk[0], m = nmk[0]>nmk[1]?nmk[0]:nmk[1], k = nmk[2];
            if (n + m < k + 2) { Console.WriteLine("-1"); return; }
            if (n + m == k + 2) { Console.WriteLine("1"); return; }
            //x:x parts,y:y parts
            //left: x>=left ,right: x<=right
            long left = 0, right = 0, ans = 0;
            if (k <= n-1) { left = 1; right = k+1; }
            else if (k >= n && k <= m-1) { left = 1; right = n; }
            else { left = k - m + 1; right = n; }
            //
            for (long x = 1; x <= (long)Math.Sqrt(n); x++)
            {
                if (k + 2 - x <= m)
                {
                    long t = (n / x) * (m / (k + 2 - x));
                    ans = Math.Max(ans, t);
                }
            }
            for (long nDivx = 1; nDivx <= (long)Math.Sqrt(n); nDivx++)
            {
                long up = n / nDivx;
                if (right < up) up = right;
                if (k + 2 - up <= m)
                {
                    long t = nDivx * (m / (k + 2 - up));
                    ans = Math.Max(ans, t);
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

namespace Codeforces
{
    class D
    {
        //*

        static void Main(string[] args)
        {

            string s = Console.ReadLine();
            string[] splitStr = s.Split(' ');
            int n = Convert.ToInt32(splitStr[0]);
            int m = Convert.ToInt32(splitStr[1]);
            int k = Convert.ToInt32(splitStr[2]);

            int p = n * m / 2;

            while (true)
            {
                int res = 0;
                int count = 0;
                for (int i = 1; i <= m; i++)
                {
                    int b = p / i;
                    res += Math.Min(b, n);
                    if ((p % i == 0) && (b <= n)) count++;
                }
                if ((k >= res - count) && (k <= res))
                {
                    Console.WriteLine(p);
                    return;
                }
                if (k < res - count)
                {
                    p -= p / 2;
                }
                else p += p / 2;
            }
        }
         /**/
    }
}


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

namespace Codeforces
{
    class D
    {
        //*

        static void Main(string[] args)
        {

            string s = Console.ReadLine();
            string[] splitStr = s.Split(' ');
            int n = Convert.ToInt32(splitStr[0]);
            int m = Convert.ToInt32(splitStr[1]);
            long k = Convert.ToInt32(splitStr[2]);

            long p = n * m / 2;
            long d = p / 2;
            //if (p == 0) p = 1;
            while (true)
            {
                long res = 0;
                long count = 0;
                for (int i = 1; i <= m; i++)
                {
                    long b = p / i;
                    res += Math.Min(b, n);
                    if ((p % i == 0) && (b <= n)) count++;
                }
                if ((k > res - count) && (k <= res))
                {
                    Console.WriteLine(p);
                    return;
                }
                if (k <= res - count)
                {

                    p -= d;
                    d /= 2;
                    if (d == 0) d = 1;
                }
                else
                {
                    p += d;
                    d /= 2;
                    if (d == 0) d = 1;
                }
            }
        }
         /**/
    }
}


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

namespace ConsoleApp61
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp0 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = inp0[0];
            int m = inp0[1];
            int k = inp0[2];
            int start = 1;
            int end = (n*m)+1;
            while (start<end)
            {
                int mid = (start + end)/2;
                long j = GetNum(n, m, mid);
                if (j < k)
                {
                    start = mid+1;
                }

                else
                {
                    end = mid;
                }
            }
            Console.WriteLine(start-1);
        }
        static long GetNum(long n,int m,int a)
        {
            long ans = 0;
            for (int i = 1; i <= n; i++)
            {
                ans += Math.Min(m, (a-1) / i);
            }
            return ans;
        }
    }
}


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

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

#if DEBUG
			TextReader reader = new StreamReader("../../input.txt");

#else
			TextReader reader = Console.In;
#endif

			#region INIT
			int[] c1 = reader.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int[] c2 = reader.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

			int x1 = c1[0];
			int y1 = c1[1];
			int r1 = c1[2];
			int R1 = c1[3];

			int x2 = c2[0];
			int y2 = c2[1];
			int r2 = c2[2];
			int R2 = c2[3];
			#endregion

			int count = 0;

			if (AreCircleWithBallOk(x1, y1, r1, x2, y2, r2, R2)) count++;
			if (AreCircleWithBallOk(x1, y1, R1, x2, y2, r2, R2)) count++;
			if (AreCircleWithBallOk(x2, y2, r2, x1, y1, r1, R1)) count++;
			if (AreCircleWithBallOk(x2, y2, R2, x1, y1, r1, R1)) count++;

			Console.WriteLine(count);

#if DEBUG
			Console.ReadKey();
#endif

		}

		static bool AreCircleWithBallOk(int x1, int y1, int rd1, int x2, int y2, int rd2, int Rd2) {

			bool res1 = !(AreBallsIntercect(x1, y1, rd1, x2, y2, rd2) ||
						  AreBallsIntercect(x1, y1, rd1, x2, y2, Rd2));

			if (!res1) return false;

			double centersDist = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));

			double t1 = centersDist + rd2;
			double t2 = rd1;
			double t3 = centersDist + Rd2;
			if (t1 < t2 && t2 < t3) return false;

			t1 = centersDist - Rd2;
			t2 = -rd1;
			t3 = centersDist - rd2;
			if (t1 < t2 && t2 < t3) return false;

			return true;

		}

		static bool AreBallsIntercect(int x1, int y1, int rd1, int x2, int y2, int rd2) {

			double centersDist = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));

			double l1 = -rd1;
			double r1 = rd1;

			double l2 = centersDist - rd2;
			double r2 = centersDist + rd2;

			if (r1 <= l2)  return false;
			if (l1 <= l2 && r1 >= r2) return false;
			if (l2 <= l1 && r2 >= r1) return false;

			return true;

		}

	}
}


using System;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;

namespace Codeforces.R300
{
    public static class C
    {
        const int MOD = 1000000007;

        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            Contract.Requires(tr != null);
            Contract.Requires(tw != null);

            var info = CultureInfo.CurrentCulture;
            var abn = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();

            var res = Calc(abn[0], abn[1], abn[2]);

            tw.WriteLine(res);
        }

        private static int Calc(int a, int b, int n)
        {
            var res = 0L;

            for (int i = 0; i <= n; ++i)
            {
                var sum = a * (n - i) + b * i;
                if (IsGood(a, b, sum))
                {
                    res = (res + Combination(n, i)) % MOD;
                }
            }

            return (int)res;
        }

        public static int Combination(int n, int r)
        {
            var res = 1L;
            for (int i = 0; i < r; ++i)
            {
                res = res * (n - i) % MOD;
            }
            for (int i = 0; i < r; ++i)
            {
                res = ModDiv(res, r - i, MOD);
            }
            return (int)res % MOD;
        }

        public static long ModDiv(long res, int v, int mod)
        {
            return res * ModPow(v, mod - 2, mod) % mod;
        }

        public static long ModPow(long x, int n, int mod)
        {
            var res = 1L;
            for (; n > 0; n >>= 1)
            {
                if ((n & 1) == 1)
                {
                    res = res * x % mod;
                }
                x = x * x % mod;
            }
            return res;
        }

        public static bool IsExcellent(int a, int b, int n)
        {
            return IsGood(a, b, n) && IsGood(a, b, SumDigits(n));
        }

        public static bool IsGood(int a, int b, int n)
        {
            for (; n > 0; n /= 10)
            {
                var lastDigit = n % 10;

                if (lastDigit != a && lastDigit != b)
                {
                    return false;
                }
            }
            return true;
        }

        public static int SumDigits(int n)
        {
            var res = 0;

            for (; n > 0; n /= 10)
            {
                res += n % 10;
            }

            return res;
        }

        public static int Pow10(int n)
        {
            var res = 1;
            for (int i = 0; i < n; ++i)
            {
                res *= 10;
            }
            return res;
        }
    }
}


using System;

namespace K
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			long N = long.Parse(Console.ReadLine());
			Console.WriteLine(N - N / 2 - N / 3 - N / 5 - N / 7 + N / 6 + N / 10);
		}
	}
}


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

namespace ChallengePennants
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            long n = long.Parse(s);
            if (n <= 10)
            {
                Console.WriteLine(0);
            }
            else
            {
                long x = n / 2 + n / 3 + n / 5 + n / 7;
                x -= n / 6 + n / 10 + n / 14 + n / 15 + n / 21 + n / 35;
                x += n / 30 + n / 42 + n / 70 + n / 105;
                x -= n / 210;
                Console.WriteLine("{0:d}", n - x);
            }
        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        const int MAXN = 1000000007;
        static long QMul(long a, long b)
        {
            long res = 1;
            long tmp = a;

            while(b != 0)
            {
                if((b & 1) == 1)
                {
                    res *= tmp;
                    res %= MAXN;
                }
                tmp *= tmp;
                tmp %= MAXN;
                b >>= 1;
            }

            return res;
        }

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] arr = input.Select(x => Convert.ToInt32(x)).ToArray();

            int n = arr[0];
            int m = arr[1];
            int k = arr[2];

            if(k == -1 && (n+m) % 2 == -1)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine(QMul(2, (m - 1) * (n - 1)).ToString());
            }
        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        const int MAXN = 1000000007;
        static long QMul(long a, long b)
        {
            long res = 1;
            long tmp = a;

            while(b != 0)
            {
                if((b & 1L) == 1)
                {
                    res *= tmp;
                    res %= MAXN;
                }
                tmp *= tmp;
                tmp %= MAXN;
                b >>= 1;
            }

            return res;
        }

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] arr = input.Select(x => Convert.ToInt32(x)).ToArray();

            int n = arr[0];
            int m = arr[1];
            int k = arr[2];

            if(k == -1 && (n+m) % 2 == -1)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine(QMul(QMul(2, (m - 1)), (n - 1)).ToString());
            }
        }
    }
}


using System;

namespace Olymp602A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            byte n = byte.Parse(input[0]), bx = byte.Parse(input[1]);
            byte[] x = new byte[n];
            input = Console.ReadLine().Split();
            for (int i = 0; i < n; ++i) x[i] = byte.Parse(input[i]);

            input = Console.ReadLine().Split();
            byte m = byte.Parse(input[0]), by = byte.Parse(input[1]);
            byte[] y = new byte[n];
            input = Console.ReadLine().Split();
            for (int i = 0; i < m; ++i) y[i] = byte.Parse(input[i]);

            long X = 0, Y = 0;

            for (int i = 0; i < n; ++i) X += x[i] * (long)Math.Pow(bx, n - i - 1);
            for (int i = 0; i < m; ++i) Y += y[i] * (long)Math.Pow(by, m - i - 1);

            //Console.Write(X + " ");
            if (X > Y) Console.Write('>');
            else if (X < Y) Console.Write('<');
            else Console.Write('=');
            //Console.WriteLine(" " + Y);
            Console.ReadLine();
        }
    }
}


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

namespace probleme {
    class Program {
        static void Main(string[] args) {
            //Console.SetIn(new StreamReader("file.txt"));
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]), bx = int.Parse(s[1]);
            long x = 0;
            int[] vx = Array.ConvertAll(Console.ReadLine().Split(' '), tz => int.Parse(tz));
            for (int i = 0; i < n; i++) {
                x *= bx;
                x += vx[i];
            }
            s = Console.ReadLine().Split(' ');
            int m = int.Parse(s[1]), by = int.Parse(s[1]);
            long y = 0;
            int[] vy = Array.ConvertAll(Console.ReadLine().Split(' '), tz => int.Parse(tz));
            for (int i = 0; i < m; i++) {
                y *= by;
                y += vy[i];
            }
            if (x == y) {
                Console.Write('=');
            } else if (x < y) {
                Console.Write('<');
            } else {
                Console.Write('>');
            }
            //Console.ReadKey();
        }
    }
}


using System;
using System.Text;

namespace pr111
{
    class Program
    {
        public static void Main(string[] args)
        { int a,b,c,n;string s;
            n=Convert.ToInt16(Console.ReadLine());
            int[] arr;
            arr= new int[24];
            a = 0; b =0; c =0;
            string[] line=Console.ReadLine().Split();
            for (int i=0; i<line.Length; i++) {arr[i]=Convert.ToInt16(line[i]);}
            for (int i=0; i<n-1; i+=3) {a+=arr[i]; b+=arr[i+1]; c+=arr[i+2];}
            if (a>=b&&a>=c) {s="chest";} else {if(b>c){s="biceps";} else {s="back";}}
            Console.WriteLine(Convert.ToString(s));
            //Console.ReadKey(true);
        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using Number = System.Int64;
using static System.Math;
//using static MathEx;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var n = ri;
            var c = new char[n];
            var a = new int[n];
            var b = new int[n];
            for (int i = 0; i < n; i++)
            {
                c[i] = rc;
                a[i] = ri;
                b[i] = ri;
            }
            var dp = new int[1 << n, 15 * 16 / 2];
            for (int i = 0; i < 1 << n; i++)
                for (int j = 0; j < 15 * 16 / 2; j++)
                    dp[i, j] = -1000000000;
            dp[0, 0] = 0;
            for (int i = 0; i < 1 << n; i++)
                for (int j = 0; j < 15 * 16 / 2; j++)
                {
                    if (dp[i, j] < 0) continue;
                    var u = 0;
                    var v = 0;
                    for (int k = 0; k < n; k++)
                    {
                        if ((i >> k & 1) == 1)
                        {
                            if (c[k] == 'R') u++;
                            else v++;
                        }
                    }
                    for (int k = 0; k < n; k++)
                    {
                        if ((i >> k & 1) == 0)
                        {
                            var x = Min(u, a[k]);
                            var y = Min(v, b[k]);
                            dp[i | 1 << k, j + x] = Max(dp[i | 1 << k, j + x], dp[i, j] + y);
                        }
                    }
                }
            var min = 1000000000;
            for (int i = 0; i < 15 * 16 / 2; i++)
            {
                var u = a.Sum() - i;
                var v = b.Sum() - dp[(1 << n) - 1, i];
                min = Min(min, Max(u, v));
            }
            IO.Printer.Out.WriteLine(min + n);
        }

        int ri => sc.Integer();
        long rl => sc.Long();
        double rd => sc.Double();
        string rs => sc.Scan();
        char rc => sc.Char();

        [System.Diagnostics.Conditional("DEBUG")]
        void put(params object[] a) => Debug.WriteLine(string.Join(" ", a));

        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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nonSquareEquation
{
    class Program
    {
        static ulong sum(ulong n)
        {
            ulong sum = 0;
            while (n>0)
            {
                sum += n % 10;
                n /= 10;
            }
            return sum;
        }
        static void Main(string[] args)
        {
            ulong n = ulong.Parse(Console.ReadLine());
            ulong max_number = (ulong)Math.Sqrt(n);
            int number = -1;
            for (ulong i=1;i<=max_number;i++)
                if (i*i+sum(i)*i==n)
                {
                    number = (int)i;
                    break;
                }
            Console.WriteLine(number);
         }
    }
}


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

namespace nonSquareEquation
{
    class Program
    {
        static long sum(long n)
        {
            long sum = 0;
            while (n>0)
            {
                sum += n % 10;
                n /= 10;
            }
            return sum;
        }
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long max_number = (long)Math.Sqrt(n);
            int maxDigitSum = 0;
            long k = max_number;
            while (k>0)
            {
                maxDigitSum += 9;
                k /= 10;
            }
            long p = max_number - (long)maxDigitSum;
            long number = -1;
            for (long i = p; i <= max_number;i++)
                if (n%i==0 && i+sum(i)==n/i)
                {
                    number = (long)i;
                    break;
                }
                Console.WriteLine(number);

         }
    }
}


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

namespace cf233B
{
    class Program
    {
        static long sum(long n)
        {
            long r = 0;
            while (n > 0)
            {
                r += n % 10;
                n /= 10;
            }
            return r;
        }
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            for (long i = (long)Math.Sqrt(n)/2; i < (long)Math.Sqrt(n) * 2; i++)
            {
                if (i * i + sum(i) * i == n)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
            Console.WriteLine(-1);
        }
    }
}


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

namespace CodeForce
{
    class _38b
    {
        public static void Main()
        {
            var fig = new string[2];
            fig[0] = Console.ReadLine();
            fig[1] = Console.ReadLine();
            var board = new bool[8,8];
            for (var i = 0; i < 8; i++)
            {
                board[i, fig[0][0] - 'a'] = true;
                board[fig[0][1] - '1', i] = true;
            }
            var d1 = new[] {1, -1};
            var d2 = new[] {2, -2};
            board[fig[1][1] - '1', fig[1][0] - 'a'] = true;
            for (var i = 0; i < 2; i++)
            {
                for (var j = 0; j < 2; j++)
                {
                    for (var k = 0; k < 2; k++)
                    {
                        var dx = d1[j];
                        var dy = d2[k];
                        var x = fig[i][0] - 'a' + dx;
                        var y = fig[i][1] - '1' + dy;
                        if (x >= 0 && y >= 0 && x < 8 && y < 8)
                        {
                            board[y, x] = true;
                        }

                        dx = d2[k];
                        dy = d1[j];
                        x = fig[i][0] - 'a' + dx;
                        y = fig[i][1] - '1' + dy;
                        if (x >= 0 && y >= 0 && x < 8 && y < 8)
                        {
                            board[y, x] = true;
                        }
                    }
                }
            }
            var result = 0;
            for (var i = 0; i < 8; i++)
            {
                for (var j = 0; j < 8; j++)
                {
                    Console.Write(board[i, j] ? 'x' : 'o');
                    if (!board[i,j])
                    {
                        result++;
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine(result);
        }
    }
}


//#undef DEBUG

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

namespace codeforces
{
    class C
    {
        //  test
        static CodeforcesUtils CF = new CodeforcesUtils(
@"
a1
b2
");

        class Solver
        {
            public void Solve()
            {
                string s = CF.ReadLine();
                int r1 = s[0] - 'a'+1;
                int r2 = s[1] - '1'+1;
                s = CF.ReadLine();
                int k1 = s[0] - 'a'+1;
                int k2 = s[1] - '1'+1;

                b = new int[10, 10];
                for (int i = 1; i <=8; i++)
                {
                    b[r1, i] = 1;
                    b[i, r2] = 1;
                }

                b[k1, k2] = 1;

                for (int i = -2; i <= 2; i++)
                {
                    if (i == 0)
                        continue;

                    bs(r1 + i, r2 + (3 - Math.Abs(i)) );
                    bs(r1 + i, r2 -(3 - Math.Abs(i)) );
                    bs(k1 + i, k2 + 3 - Math.Abs(i) );
                    bs(k1 + i, k2 - (3 - Math.Abs(i)));
                }

                int a = 8 * 8;
                for (int i = 1; i <= 8; i++)
                {
                    for (int j = 1; j <= 8; j++)
                    {
                        a -= b[i, j];
                    }
                }

                CF.WriteLine(a);
            }

            int[,] b;

            void bs(int x, int y)
            {
                if (x < 1 || y > 8)
                    return;
                if (y < 1 || y > 8)
                    return;
                b[x, y] = 1;
            }
        }

        #region test

        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ru-RU");

            new Solver().Solve();
            CF.Close();
        }

        static void TLE()
        {
            for (; ; ) ;
        }

        class CodeforcesUtils
        {
            public string ReadLine()
            {
#if DEBUG
                if (_lines == null)
                {
                    _lines = new List<string>();
                    string[] ss = _test_input.Replace("\n", "").Split('\r');
                    for (int i = 0; i < ss.Length; i++)
                    {
                        if (
                            (i == 0 || i == ss.Length - 1) &&
                            ss[i].Length == 0
                            )
                            continue;

                        _lines.Add(ss[i]);
                    }
                }

                string s = null;
                if (_lines.Count > 0)
                {
                    s = _lines[0];
                    _lines.RemoveAt(0);
                }
                return s;

#else
                //return _sr.ReadLine();
            return Console.In.ReadLine();
#endif
            }

            public void WriteLine(object o)
            {
#if DEBUG
                System.Diagnostics.Trace.WriteLine(o);
#else
                //_sw.WriteLine(o);
            Console.WriteLine(o);
#endif
            }

            public void Write(object o)
            {
#if DEBUG
                System.Diagnostics.Trace.Write(o);
#else
                 //_sw.Write(o);
           Console.Write(o);
#endif
            }

            string _test_input;

            List<string> _lines;

#if DEBUG
            public CodeforcesUtils(string test_input)
            {
                _test_input = test_input;
            }
#else

            public CodeforcesUtils(string dummy)
            {
                //_sr = new System.IO.StreamReader("input.txt");
                //_sw = new System.IO.StreamWriter("output.txt");
            }
#endif

            public void Close()
            {
                if( _sr!= null)
                    _sr.Close();
                if( _sw != null)
                    _sw.Close();
            }

            System.IO.StreamReader _sr=null;
            System.IO.StreamWriter _sw=null;

        }

        #endregion
    }
}


using System;

class A448 {
    public static void Main() {
        var a = Console.ReadLine().Split().Sum(int.Parse);
        var b = Console.ReadLine().Split().Sum(int.Parse);
        var n = int.Parse(Console.ReadLine());
        Console.WriteLine((a + 4) / 5 + (b + 9) / 10 <= n ? "YES" : "NO");
    }
}


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

namespace Preparation
{
    public class CodeForces710A
    {
        public void Main(string[] args)
        {
            var str = Console.ReadLine();
            if(str[0] == 'a' && str[1] == '1' ||
               str[0] == 'a' && str[1] == '8' ||
               str[0] == 'h' && str[1] == '1' ||
               str[0] == 'h' && str[1] == '8')
                Console.WriteLine(3);
            else if(str[0] == 'h' || str[1] == '8' || str[0] == 'a' || str[1] == '1')
                Console.WriteLine(5);
            else
                Console.WriteLine(8);
        }
    }
}


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

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] Input = Console.ReadLine().Split(' ');
            int a = 1;
            int b = 1;
            string c = "";
            string d = "";
            if (Input[0].Length >= 8)
            {
                for (var j = 0; j < 8; j++)
                {
                    c += Input[0][Input[0].Length - 8 + j];
                }
            }
            else
            {
                c = Input[0];
            }
            if (Input[1].Length >= 8)
            {
                for (var j = 0; j < 8; j++)
                {
                    d += Input[1][Input[1].Length - 8 + j];
                }
            }
            else
            {
                {
                    d = Input[1];
                }
            }
            a = Convert.ToInt32(c);
            b = Convert.ToInt32(d);
            int result = 1;
            if (a == 0 || b == 0)
            {
                result = 0;
            }
            for (int i = a + 1; i <= b; i++)
            {
                result = Convert.ToInt32(Convert.ToString(Convert.ToString(result)[Convert.ToString(result).Length - 1]))%100;

                if (i == 0 || result == 0)
                {
                    result = 0;
                    continue;
                }
                else
                {
                    result *= Convert.ToInt32(Convert.ToString(Convert.ToString(i)[Convert.ToString(i).Length - 1]))%100;
                }
            }
            string ans = Convert.ToString(result);
            Console.WriteLine(ans[ans.Length - 1]);

        }
    }
}


using System;

namespace _869_B
{
    class MyClass
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            ulong a = ulong.Parse(s[0]), b = ulong.Parse(s[1]), Ans;
            if (b == a) Ans = 1;
            else
            {
                ulong result = 1;
                for (ulong i = a+1; i <= b; i++)
                    result = result * (i%10);
                Ans = result;
            }
            Console.WriteLine(Ans%10);
        }
    }
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            long a, b, lstTkn = 1;
            {
                string[] input = Console.ReadLine().Split(new char[] { ' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
                a = int.Parse(input[0]);
                b = int.Parse(input[1]);
                if (a == 0) { a++; if (b == 0) b++; }
            }
            while(++a<=b)
            {
                lstTkn *= (a%10);
                lstTkn %= 10;
            }
            Console.WriteLine(lstTkn);
        }
    }


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
             string[]y=Console.ReadLine().Split(' ');
             int[]a=new int[3];
             a[0]=int.Parse(y[0]);
             a[1]=int.Parse(y[1]);
             a[2]=int.Parse(y[2]);
             int n=int.Parse(y[3]);
             Array.Sort(a);
             int o1=a[1]-n;
             int o2=a[1]+n;
             int t=0;
             while(a[0]>o1)
             {
                  a[0]--;
                  t++;
             }
             while(a[2]<o2)
             {
                  a[2]++;
                  t++;
             }
             Console.WriteLine(t);

        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {

        static void Main(string[] args)
        {

            var abcd = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = abcd[0];
            var b = abcd[1];
            var c = abcd[2];
            var d = abcd[3];

            var list = new List<int>(3) { a, b, c };
            list.Sort();
            var left = d - (list[1] - list[0]);
            var right = d - (list[2] - list[1]);
            Console.WriteLine(left + right);
        }

    }
}


using System;
using System.Linq;

namespace CSharp
{
    public class _478C
    {
        public static void Main()
        {
            int[] counts = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();

            int sum = counts.Sum();
            int max = counts.Max();

            Console.WriteLine(2 * sum >= 3 * max ? sum / 3 : sum - max);
        }
    }
}


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

namespace CodeForce
{
    class Program
    {
        static void Main(string[] args)
        {
            int s, v1, v2, t1, t2;
            s = int.Parse(Console.ReadLine());
            v1 = int.Parse(Console.ReadLine());
            v2 = int.Parse(Console.ReadLine());
            t1 = int.Parse(Console.ReadLine());
            t2 = int.Parse(Console.ReadLine());

            int sum1 = 0;
            int sum2 = 0;

            sum1 = v1 * s + 2 * t1;
            sum2 = v2 * s + 2 * t2;

            if (sum1 < sum2)
            Console.WriteLine("First");

            if (sum2 < sum1)
                Console.WriteLine("Second");

            if(sum1 == sum2)
                Console.WriteLine("Friendship");

        }
    }
}


using System;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var input = args[0].Split().Select(x => Convert.ToInt32(x)).ToList();
        var s = input[0];
        var v1 = input[1];
        var v2 = input[2];
        var t1 = input[3];
        var t2 = input[4];
        var r1 = t1 * 2 + s * v1;
        var r2 = t2 * 2 + s * v2;
        if (r1 < r2)
        {
            Console.WriteLine("First");
        }
        else if (r1 > r2)
        {
            Console.WriteLine("Second");
        }
        else
        {
            Console.WriteLine("Friendship");
        }
    }
}


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

namespace SortingProblems
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list = new List<int>();
            int length = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < length; i++)
            {
                list.Add(Convert.ToInt32(Console.ReadLine()));
            }
            var sorted  = SortMerge(list);
            int current = 0;
            for (int i = 0; i < sorted.Count; i = i + 2)
            {
                current += sorted[i + 1] - sorted[i];
            }
            Console.WriteLine(current);
        }

        static List<int> SortMerge(List<int> list)
        {
            if (list.Count <= 1) return list;
            List<int> left = new List<int>();
            List<int> right = new List<int>();

            for (int i = 0; i < list.Count / 2; i++)
            {
                left.Add(list[i]);
            }

            for (int i = list.Count / 2; i < list.Count; i++)
            {
                right.Add(list[i]);
            }

            left = SortMerge(left);
            right = SortMerge(right);
            return Merge(left, right);
        }

        static List<int> Merge(List<int> left, List<int> right)
        {
            List<int> merged = new List<int>();
            while (left.Count > 0 || right.Count > 0)
            {
                if (left.Count > 0 && right.Count > 0)
                {
                    if (left.First() <= right.First())
                    {
                        merged.Add(left.First());
                        left.Remove(left.First());
                    }
                    else
                    {
                        merged.Add(right.First());
                        right.Remove(right.First());
                    }
                }
                else if (left.Count > 0)
                {
                    merged.Add(left.First());
                    left.Remove(left.First());
                }
                else if (right.Count > 0)
                {
                    merged.Add(right.First());
                    right.Remove(right.First());
                }
            }
            return merged;
        }

    }
}


using System.Collections.Generic;
using System;
namespace ProblemToAlgorithms
{
class Solution
{
    public static int arrayManipulation(List<int> list)
    {
        int sum = 0;
        for (int i = 0; i < list.Count; i++)
        {
            var next = list[i];
            int j = i - 1;
            while (j >= 0 && list[j] > next)
            {
                list[j + 1] = list[j];
                --j;
            }
            list[j + 1] = next;
        }
        for (int i = 0; i < list.Count; i += 2)
        {
            sum = sum + list[i + 1] - list[i];
        }
        return sum;
    }

    static void Main(string[] args)
    {
        List<int> list = new List<int>();
            string t = Console.ReadLine();
            String []coll = t.Split(' ');
            foreach (var item in coll)
            {
                list.Add(Int32.Parse(item));
            }
        var i = Solution.arrayManipulation(list);
        Console.WriteLine(i);

    }
}

}


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

namespace _112_b
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.SetIn(File.OpenText("in.txt"));
			var d = Console.ReadLine().Split(' ').Select(l => int.Parse(l)).ToArray();
			var n = d[0];
			var k = d[1];

			var min = 0;
			var max = n;
			while (true)
			{
				if (min == max)
				{
					break;
				}

				var m = min + (max - min) / 2;
				var written = m;
				var koeff = k;
				while (true)
				{
					var next = m / koeff;
					if (next == 0)
					{
						break;
					}

					koeff *= k;
					written += next;
				}

				if (written >= n)
				{
					max = m;
				}
				else
				{
					min = m + 1;
				}
			}

			Console.WriteLine(min);
		}
	}
}