using System;
using System.Collections.Generic;

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

namespace Codeforces
{
    public class Input
    {
        private static string _line;

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

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

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

            return ok;
        }

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

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

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

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

        public static bool Next(out string value)
        {
            value = string.Empty;
            if (!Next()) return false;
            value = _line;
            return true;
        }
    }

    public class DisjointSet
    {
        private readonly int[] _parent;
        private readonly int[] _rank;
        public int Count { get; private set; }

        public DisjointSet(int count, int initialize = 0)
        {
            Count = count;
            _parent = new int[Count];
            _rank = new int[Count];
            for (var i = 0; i < initialize; i++) _parent[i] = i;
        }

        private DisjointSet(int count, int[] parent, int[] rank)
        {
            Count = count;
            _parent = parent;
            _rank = rank;
        }

        public void Add(int v)
        {
            _parent[v] = v;
            _rank[v] = 0;
        }

        public int Find_Recursive(int v)
        {
            if (_parent[v] == v) return v;
            return _parent[v] = Find(_parent[v]);
        }

        public int Find(int v)
        {
            if (_parent[v] == v) return v;
            var last = v;
            while (_parent[last] != last) last = _parent[last];
            while (_parent[v] != v)
            {
                var t = _parent[v];
                _parent[v] = last;
                v = t;
            }
            return last;
        }

        public int this[int v]
        {
            get { return Find(v); }
            set { Union(v, value); }
        }

        public void Union(int a, int b)
        {
            a = Find(a);
            b = Find(b);
            if (a == b) return;
            if (_rank[a] < _rank[b])
            {
                var t = _rank[a];
                _rank[a] = _rank[b];
                _rank[b] = t;
            }
            _parent[b] = a;
            if (_rank[a] == _rank[b]) _rank[a]++;
        }

        public int GetSetCount()
        {
            var result = 0;
            for (var i = 0; i < Count; i++)
            {
                if (_parent[i] == i) result++;
            }
            return result;
        }

        public DisjointSet Clone()
        {
            var rank = new int[Count];
            _rank.CopyTo(rank, 0);
            var parent = new int[Count];
            _parent.CopyTo(parent, 0);
            return new DisjointSet(Count, parent, rank);
        }

        public override string ToString()
        {
            return string.Join(",", _parent.Take(50));
        }
    }

    public class Matrix
    {
        public static Matrix Create(int i, int j)
        {
            var m = new Matrix(i, j);
            return m;
        }

        public static Matrix Create(int i)
        {
            var m = new Matrix(i, i);
            return m;
        }

        public long Modulo { get; set; }

        private readonly int _width;
        private readonly int _height;
        private readonly long[,] _data;
        public int Width{get { return _width; }}
        public int Height{get { return _height; }}

        private Matrix(int i, int j)
        {
            Modulo = 1000000000000000000L;
            _width = j;
            _height = i;
            _data = new long[_height, _width];
        }

        public static Matrix operator *(Matrix m1, Matrix m2)
        {
            if (m1.Width != m2.Height) throw new InvalidDataException("m1.Width != m2.Height");
            var m = Create(m2.Width, m1.Height);
            m.Modulo = m1.Modulo;
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                {
                    for (var k = 0; k < m1.Width; k++)
                        m[j, i] += (m1[j, k]*m2[k, i]) % m1.Modulo;
                    m[j, i] %= m1.Modulo;
                }
            return m;
        }

        public static Matrix operator +(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] + m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator -(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] - m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator *(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i=0;i<m1.Width;i++)
                for (var j=0;j<m1.Height;j++)
                        m[j, i] = (m[j, i] * l) % m.Modulo;
            return m;
        }

        public static Matrix operator *(long l, Matrix m1)
        {
            return m1*l;
        }

        public static Matrix operator +(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i = 0; i < m1.Width; i++)
                    m[i, i] = (m[i, i] + l) % m.Modulo;
            return m;
        }

        public static Matrix operator +(long l, Matrix m1)
        {
            return m1 + l;
        }

        public static Matrix operator -(Matrix m1, long l)
        {
            return m1 + (-l);
        }

        public static Matrix operator -(long l, Matrix m1)
        {
            var m = m1.Clone() * -1;
            return m + l;
        }

        public Matrix BinPower(long l)
        {
            var n = 1;
            var m = Clone();
            var result = new Matrix(m.Height, m.Width) + 1;
            result.Modulo = m.Modulo;
            while (l != 0)
            {
                var i = l & ~(l - 1);
                l -= i;
                while (n < i)
                {
                    m = m*m;
                    n <<= 1;
                }
                result *= m;
            }
            return result;
        }

        public void Fill(long l)
        {
            l %= Modulo;
            for (var i = 0; i < _height; i++)
                for (var j = 0; j < _width; j++)
                    _data[i, j] = l;
        }

        public Matrix Clone()
        {
            var m = new Matrix(_width, _height);
            Array.Copy(_data, m._data, _data.Length);
            m.Modulo = Modulo;
            return m;
        }

        public long this[int i, int j]
        {
            get { return _data[i, j]; }
            set { _data[i, j] = value % Modulo; }
        }
    }
}

namespace Codeforces.TaskE
{
    public class Task
    {
        public static void Main()
        {
            var task = new Task();
            try
            {
                task.Solve();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
                throw;
            }
        }

        bool Check(long b, long a)
        {
            if (a == 0) return false;
            if (!Check(a, b%a)) return true;
            var c = b/a;
            return c%(a+1)%2==0;
        }

        void Solve()
        {
            long t;
            Input.Next(out t);

            var l = new List<string>();
            for (var i = 0; i < t; i++)
            {
                long a, b;
                Input.Next(out a, out b);
                if (a < b)
                {
                    var c = b;
                    b = a;
                    a = c;
                }
                l.Add(Check(a,b) ? "First" : "Second");
            }
            Console.WriteLine(string.Join(Environment.NewLine, l));
        }
    }
}


using System;
class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("INTERCAL");
        }
    }


using System;

public sealed class Program {

  const Int64 Mod = 1000000007;

  static void Add(ref Int64 cur, Int64 add) {
    cur = (cur + add) % Mod;
  }

  static Tuple<Int32, Int32> Solve() {
    Int32 n = ReadInt(), cap = ReadInt(), i, cnt50 = 0, cnt100 = 0, a, b, c, d;
    for (i = 0; i < n; ++i) {
      if (ReadInt() == 50) {
        ++cnt50;
      } else {
        ++cnt100;
      }
    }
    Int64[,] binomial = new Int64[n + 1, n + 1];
    for (i = 0; i <= n; ++i) {
      binomial[i, 0] = binomial[i, i] = 1;
    }
    for (a = 2; a <= n; ++a) {
      for (b = 1; b < a; ++b) {
        binomial[a, b] = (binomial[a - 1, b] + binomial[a - 1, b - 1]) % Mod;
      }
    }
    Int64[, ,] dp = new Int64[n * 2 + 1, cnt50 + 1, cnt100 + 1];
    dp[0, cnt50, cnt100] = 1;
    for (i = 0; ; ++i) {
      if (i == n * 2) {
        return Tuple.Create(-1, 0);
      } else if (i % 2 != 0 && dp[i, cnt50, cnt100] != 0) {
        return Tuple.Create(i, (Int32)dp[i, cnt50, cnt100]);
      }
      for (a = 0; a <= cnt50; ++a) {
        for (b = 0; b <= cnt100; ++b) {
          if (dp[i, a, b] != 0) {
            for (c = 0; c <= a; ++c) {
              for (d = 0; d <= b && c * 50 + d * 100 <= cap; ++d) {
                if (c + d != 0) {
                  Add(ref dp[i + 1, cnt50 - (a - c), cnt100 - (b - d)], dp[i, a, b] * binomial[a, c] % Mod * binomial[b, d] % Mod);
                }
              }
            }
          }
        }
      }
    }
  }

  // stuff cutline

  public static void Main() {
#if DEBUG
    Console.SetIn(new System.IO.StreamReader("..\\..\\in.txt"));
#endif
    var ans = Solve();
    Console.WriteLine(ans.Item1);
    Console.WriteLine(ans.Item2);
  }

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

  static Int32[] ReadArray() {
    return Array.ConvertAll<String, Int32>(Console.ReadLine().Split(), Int32.Parse);
  }

}


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, a, b, c, count = 0;
            string[] buff = Console.ReadLine().Split(' ');
            N = int.Parse(buff[0]);
            a = int.Parse(buff[1]);
            b = int.Parse(buff[2]);
            c = int.Parse(buff[3]);

            for (int i = 0; i <= c; i++)
            {
                int mod1;
                mod1 = N - i*2;
                if (mod1 < 0)
                {
                    continue;
                }
                if (mod1 == 0)
                {
                    count++;
                    continue;
                }
                for (int j = 0; j <= b; j++)
                {
                    int mod2;
                        mod2 = mod1 - j;
                    if (mod2 < 0)
                    {
                        continue;
                    }
                    if (mod2 == 0)
                    {
                        count++;
                        continue;
                    }
                    if (a * 0.5 >= mod2)
                        count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

public static partial class MyExtension
{
    public class Solution
    {
        /* Head ends here */

        public const int PAD_FACTOR = 7;

        public static int greedy(int a, int b, int f, int k)
        {
            var ans = 0;
            var stock = b;
            var spbu = f;
            while (k-- > 0)
            {
                var canSpbu = stock >= spbu;
                if (!canSpbu)
                    return -1;
                // decide whether to refill or not
                var canStopNoRefill = stock >= a;
                var last = k == 0;
                var nextSpbu = a - spbu;
                var nextCanSpbuNoRefill = stock >= (a + nextSpbu);
                var skipRefill = new Func<bool>(() =>
                {
                    if (last) return canStopNoRefill;
                    return nextCanSpbuNoRefill;
                });
                // simul
                stock -= spbu;  // to spbu
                if(stock < 0)
                    return -1;
                if (skipRefill() == false)
                {
                    // refill
                    stock = b;
                    ans++;
                }
                stock -= (a - spbu);    // to stop
                if(stock < 0)
                    return -1;
                // next loop
                spbu = a - spbu;
            }
            return ans;
        }

        int solve()
        {
            // a, b, f, k (0 < f < a ≤ e6, 1 ≤ b ≤ e9, 1 ≤ k ≤ e4)
            var A = ReadInt32();//e6
            var B = ReadInt32();//e6
            var F = ReadInt32();//e9
            var K = ReadInt32();//e4
            // only refill if necessary -> can't finish k
            return greedy(A, B, F, K);
            // Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1.
        }

        public void zStart()
        {
            Console.WriteLine(solve());

            ///////////////////////////////////////

            //foreach (var @__ in Enumerable.Range(1, ReadInt32()))
            //{
                // start... - no CONSOLE

                // end...

                //var ansLines = new List<string>(9999);
                //{
                //    // ANS start...

                //    //ansLines.AddRange(inp.Select(x => new string(x)));
                //    //...

                //    Console.Write("Case #{0}: ", @__);
                //    Console.WriteLine(string.Join(" ", __getFormattedString(ans)));
                //    ansLines.ForEach(x => Console.WriteLine(x));
                //}
                //Trace.WriteLine(string.Format("DONE_{0}.", @__));
            //}
        }

        T __getFormattedString<T>(T val) { return val; }
#if DEBUG
        string __getFormattedString(double d) { return d.ToString("0.000000"); }
#endif
        /* Tail starts here */
    }

#if TORIQ
    static void Pretest()
    {
        assert(Solution.greedy(6, 9, 2, 4), 4);
        assert(Solution.greedy(6, 10, 2, 4), 2);
        assert(Solution.greedy(2, 1, 1, 1), 1);
    }
    static void MainTest()
    {
        Test(File.ReadAllText("input.txt")
            , File.ReadAllText("output.txt")
            );
        //
    }
#endif

    // =============================================================================================

    #region faSTDIO
    [DebuggerNonUserCode]
    static void Main(String[] args)
    {
#if TORIQ
        zTestSuite();
        //new Solution().zInternalTestSuite();
        return;
#endif
#if GOOGLE
        zGoogle();
        return;
#endif
        new Solution().zStart();
    }

    static IEnumerable<char> Read()
    {
        int cin;
        var empty = true;
        while ((cin = Console.Read()) > -1)
        {
            var c = (char)cin;
            if (c == ' ' || c == '\n' || c == '\r' || c == '\t')
            {
                if (empty) continue;
                else break;
            }
            yield return c;
            empty = false;
        }
    }
    static T Read<T>(Converter<string, T> convert, int capacity = 20)
    { var temp = ReadString(capacity); return convert(temp); }
    static string ReadString(int capacity = 1000000)
    {
        capacity += Solution.PAD_FACTOR;
        var ans = new System.Text.StringBuilder(capacity);
        foreach (var c in Read()) ans.Append(c);
        return ans.ToString();
    }
    static string ReadLine(int capacity = 1000000)
    {
        capacity += Solution.PAD_FACTOR;
        var ans = Console.ReadLine();
        if (string.IsNullOrWhiteSpace(ans.Trim()))
            ans = Console.ReadLine();
        return ans;
    }
    static int ReadInt32() { return Read(Convert.ToInt32); }
    static long ReadLong64() { return Read(Convert.ToInt64); }

    #endregion
    #region Convert
    public static int int32(this long i64) { return Convert.ToInt32(i64); }
    public static int int32(this double dec64) { return Convert.ToInt32(dec64); }
    public static long long64(this int i32) { return (long)i32; }
    public static long long64(this double dec64) { return Convert.ToInt64(dec64); }
    public static double double64(this long i64) { return Convert.ToDouble(i64); }
    public static double double64(this int i32) { return (double)i32; }
    #endregion
    #region LIBS
    [DebuggerNonUserCode]
    public static void assert(bool mustBeTrue, string message = "ASSERTION FAILED", params object[] args)
    {
        if (mustBeTrue == false)
            throw new ApplicationException(string.Format(message, args));
    }

    [DebuggerNonUserCode]
    public static T assert<T>(T actual, T expected)
    {
        if (object.Equals(actual, expected) == false)
        {
            Debug.WriteLine(expected, "CORRECT");
            Debug.WriteLine(actual, "ACTUAL");
            assert(false, "[{0}] SHOULD BE [{1}]", actual, expected);
        }
        return actual;
    }

    [Conditional("DEBUG")]
    public static void EmptyConditionalDebugBreak() { }

    public static bool isLrLeftRight<T>(T left, T right) where T : IComparable<T>
    { return left.CompareTo(right) <= 0; }

    [DebuggerNonUserCode]
    public static void lrLeftRight_ASSERT<T>(T left, T right) where T : IComparable<T>
    { assert(isLrLeftRight(left, right), "Expect left [{0}] <= [{1}] right", left, right); }

    public static IEnumerable<T> forEach<T>(this IEnumerable<T> range, Action<T> action)
    { foreach (var elem in range) action(elem); return range; }

    [DebuggerNonUserCode]
    public static void __AssertIncrStep(double incrStep) { assert(incrStep > 0, "Expect 'incrStep [{0}] > 0'", incrStep); }

    public static long add64(long a, long b) { return a + b; }
    public static long mult64(long a, long b) { return a * b; }
    public static double div(double dividend, double divisor) { return dividend / divisor; }
    public static int ceil(double d) { return Convert.ToInt32(Math.Ceiling(d)); }
    public static int ceil(double dividend, double divisor) { return ceil(div(dividend, divisor)); }
    public static long ceil64(double d) { return Convert.ToInt64(Math.Ceiling(d)); }
    public static int floor(double d) { return Convert.ToInt32(Math.Floor(d)); }
    public static int floor(double dividend, double divisor) { return floor(div(dividend, divisor)); }
    public static long floor64(double d) { return Convert.ToInt64(Math.Floor(d)); }

    public static IEnumerable<int> rangeUntil(int left, int right, int incrStep = 1)
    {
        lrLeftRight_ASSERT(left, right);
        __AssertIncrStep(incrStep);
        for (var i = left; i <= right; i += incrStep) yield return i;
    }
    public static IEnumerable<int> rangeReverse(int left, int right, int decrStep = 1)
    {
        lrLeftRight_ASSERT(left, right);
        __AssertIncrStep(decrStep);
        for (var i = right; i >= left; i -= decrStep) yield return i;
    }

    #endregion

    // =============================================================================================

}


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

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

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

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

        public void Solve()
        {
            var a = sr.NextInt64();
            var b = sr.NextInt64();
            var f = sr.NextInt64();
            var k = sr.NextInt64();

            var currB = b;
            var count = 0L;
            for (var i = 0; i < k; i++) {
                var firstStation = i % 2 == 0 ? f : a - f;
                var secondStation = i % 2 == 0 ? 2*a - f : a + f;
                if (i + 1 == k) {
                    if (currB - a >= 0) {
                        break;
                    }
                    else {
                        if (currB < firstStation) {
                            sw.WriteLine(-1);
                            return;
                        }
                        if (b < (a - firstStation)) {
                            sw.WriteLine(-1);
                            return;
                        }
                        count++;
                        break;
                    }
                }
                if (currB < firstStation) {
                    sw.WriteLine(-1);
                    return;
                }
                if (currB >= secondStation) {
                    currB -= a;
                }
                else {
                    currB = b - (a - firstStation);
                    count++;
                }
            }

            sw.WriteLine(count);
        }

        ~Task()
        {
            Dispose(false);
        }

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

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

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

                isDispose = true;
            }
        }
    }
}

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

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

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

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

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

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

        return buffer[seek++];
    }

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

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

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

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

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

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

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

            isDispose = true;
        }
    }

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


using System;

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

namespace Codeforces
{
    public class Input
    {
        private static string _line;

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

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

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

            return ok;
        }

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

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

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

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

        public static bool Next(out string value)
        {
            value = string.Empty;
            if (!Next()) return false;
            value = _line;
            return true;
        }
    }

    public class DisjointSet
    {
        private readonly int[] _parent;
        private readonly int[] _rank;
        public int Count { get; private set; }

        public DisjointSet(int count, int initialize = 0)
        {
            Count = count;
            _parent = new int[Count];
            _rank = new int[Count];
            for (var i = 0; i < initialize; i++) _parent[i] = i;
        }

        private DisjointSet(int count, int[] parent, int[] rank)
        {
            Count = count;
            _parent = parent;
            _rank = rank;
        }

        public void Add(int v)
        {
            _parent[v] = v;
            _rank[v] = 0;
        }

        public int Find_Recursive(int v)
        {
            if (_parent[v] == v) return v;
            return _parent[v] = Find(_parent[v]);
        }

        public int Find(int v)
        {
            if (_parent[v] == v) return v;
            var last = v;
            while (_parent[last] != last) last = _parent[last];
            while (_parent[v] != v)
            {
                var t = _parent[v];
                _parent[v] = last;
                v = t;
            }
            return last;
        }

        public int this[int v]
        {
            get { return Find(v); }
            set { Union(v, value); }
        }

        public void Union(int a, int b)
        {
            a = Find(a);
            b = Find(b);
            if (a == b) return;
            if (_rank[a] < _rank[b])
            {
                var t = _rank[a];
                _rank[a] = _rank[b];
                _rank[b] = t;
            }
            _parent[b] = a;
            if (_rank[a] == _rank[b]) _rank[a]++;
        }

        public int GetSetCount()
        {
            var result = 0;
            for (var i = 0; i < Count; i++)
            {
                if (_parent[i] == i) result++;
            }
            return result;
        }

        public DisjointSet Clone()
        {
            var rank = new int[Count];
            _rank.CopyTo(rank, 0);
            var parent = new int[Count];
            _parent.CopyTo(parent, 0);
            return new DisjointSet(Count, parent, rank);
        }

        public override string ToString()
        {
            return string.Join(",", _parent.Take(50));
        }
    }

    public class Matrix
    {
        public static Matrix Create(int i, int j)
        {
            var m = new Matrix(i, j);
            return m;
        }

        public static Matrix Create(int i)
        {
            var m = new Matrix(i, i);
            return m;
        }

        public long Modulo { get; set; }

        private readonly int _width;
        private readonly int _height;
        private readonly long[,] _data;
        public int Width{get { return _width; }}
        public int Height{get { return _height; }}

        private Matrix(int i, int j)
        {
            Modulo = 1000000000000000000L;
            _width = j;
            _height = i;
            _data = new long[_height, _width];
        }

        public static Matrix operator *(Matrix m1, Matrix m2)
        {
            if (m1.Width != m2.Height) throw new InvalidDataException("m1.Width != m2.Height");
            var m = Create(m2.Width, m1.Height);
            m.Modulo = m1.Modulo;
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                {
                    for (var k = 0; k < m1.Width; k++)
                        m[j, i] += (m1[j, k]*m2[k, i]) % m1.Modulo;
                    m[j, i] %= m1.Modulo;
                }
            return m;
        }

        public static Matrix operator +(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] + m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator -(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] - m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator *(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i=0;i<m1.Width;i++)
                for (var j=0;j<m1.Height;j++)
                        m[j, i] = (m[j, i] * l) % m.Modulo;
            return m;
        }

        public static Matrix operator *(long l, Matrix m1)
        {
            return m1*l;
        }

        public static Matrix operator +(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i = 0; i < m1.Width; i++)
                    m[i, i] = (m[i, i] + l) % m.Modulo;
            return m;
        }

        public static Matrix operator +(long l, Matrix m1)
        {
            return m1 + l;
        }

        public static Matrix operator -(Matrix m1, long l)
        {
            return m1 + (-l);
        }

        public static Matrix operator -(long l, Matrix m1)
        {
            var m = m1.Clone() * -1;
            return m + l;
        }

        public Matrix BinPower(long l)
        {
            var n = 1;
            var m = Clone();
            var result = new Matrix(m.Height, m.Width) + 1;
            result.Modulo = m.Modulo;
            while (l != 0)
            {
                var i = l & ~(l - 1);
                l -= i;
                while (n < i)
                {
                    m = m*m;
                    n <<= 1;
                }
                result *= m;
            }
            return result;
        }

        public void Fill(long l)
        {
            l %= Modulo;
            for (var i = 0; i < _height; i++)
                for (var j = 0; j < _width; j++)
                    _data[i, j] = l;
        }

        public Matrix Clone()
        {
            var m = new Matrix(_width, _height);
            Array.Copy(_data, m._data, _data.Length);
            m.Modulo = Modulo;
            return m;
        }

        public long this[int i, int j]
        {
            get { return _data[i, j]; }
            set { _data[i, j] = value % Modulo; }
        }
    }

    public class RedBlackTree<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
    {
        private readonly List<Node> _items = new List<Node>();
        private Node _root;
        private readonly IComparer<TKey> _comparer;

        public RedBlackTree()
        {
            _comparer = Comparer<TKey>.Default;
        }

        private Node _search(TKey key)
        {
            var node = _root;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return node;
                node = i > 0 ? node.Right : node.Left;
            }
            return null;
        }

        public void Add(TKey key, TValue value)
        {
            var node = new Node { Key = key, Value = value, Red = true };
            _items.Add(node);
            if (_root == null)
            {
                _root = node;
                _root.Red = false;
                return;
            }
            var x = _root;
            Node y = null;
            while (x != null)
            {
                y = x;
                x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;
            }
            node.Parent = y;
            if (y == null) _root = node;
            else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;
            else y.Left = node;
            InsertFixup(node);
        }

        private void InsertFixup(Node node)
        {
            while (true)
            {
                var parent = node.Parent;
                if (parent == null || !parent.Red || parent.Parent == null) break;
                var grand = parent.Parent;

                if (parent == grand.Left)
                {
                    var uncle = grand.Right;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Right) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateLeft(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateRight(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
                else
                {
                    if (_root.Parent != null) Debugger.Break();

                    var uncle = grand.Left;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Left) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateRight(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateLeft(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
            }
            _root.Red = false;
        }

        private void RotateLeft(Node node)
        {
            if (node.Right == null)
                throw new NotSupportedException("Cannot rotate left: right node is missing");
            var parent = node.Parent;
            var right = node.Right;
            right.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = right;
                else parent.Right = right;
            }
            node.Right = right.Left;
            if (node.Right != null)
                node.Right.Parent = node;
            right.Left = node;
            node.Parent = right;
        }

        private void RotateRight(Node node)
        {
            if (node.Left == null)
                throw new NotSupportedException("Cannot rotate right: left node is missing");
            var parent = node.Parent;
            var left = node.Left;
            left.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = left;
                else parent.Right = left;
            }
            node.Left = left.Right;
            if (node.Left != null)
                node.Left.Parent = node;
            left.Right = node;
            node.Parent = left;
        }

        public void Remove(TKey key)
        {
            var node = _search(key);
            if (node == null) return;

            var deleted = node.Left == null || node.Right == null ? node : Next(node);
            var child = deleted.Left ?? deleted.Right;
            if (child != null)
                child.Parent = deleted.Parent;
            if (deleted.Parent == null) /* root */
                _root = child;
            else if (deleted == deleted.Parent.Left)
                deleted.Parent.Left = child;
            else
                deleted.Parent.Right = child;
            if (node != deleted)
            {
                node.Key = deleted.Key;
                node.Value = deleted.Value;
            }

            if (!deleted.Red)
            {
                DeleteFixup(child, deleted.Parent);
            }
        }

        private void DeleteFixup(Node node, Node parent)
        {
            while (parent != null && (node == null || !node.Red))
            {
                if (node == parent.Left)
                {
                    var brother = parent.Right;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateLeft(parent);
                        brother = parent.Right;
                    }
                    if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Right == null || !brother.Right.Red)
                        {
                            if (brother.Left != null)
                                brother.Left.Red = false;
                            brother.Red = true;
                            RotateRight(brother);
                            brother = parent.Right;
                        }
                        if (!brother.Right.Red) Debugger.Break();
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Right != null)
                            brother.Right.Red = false;
                        RotateLeft(parent);
                        node = _root;
                    }
                }
                else
                {
                    var brother = parent.Left;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateRight(parent);
                        brother = parent.Left;
                    }
                    if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Left == null || !brother.Left.Red)
                        {
                            if (brother.Right != null)
                                brother.Right.Red = false;
                            brother.Red = true;
                            RotateLeft(brother);
                            brother = parent.Left;
                        }
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Left != null)
                            brother.Left.Red = false;
                        RotateRight(parent);
                        node = _root;
                    }
                }
                parent = node.Parent;
            }

            node.Red = false;
        }

        public TValue this[TKey key]
        {
            get
            {
                var node = _search(key);
                return node == null ? default(TValue) : node.Value;
            }
            set
            {
                var node = _search(key);
                if (node == null) Add(key, value);
                else node.Value = value;
            }
        }

        public bool Check()
        {
            int count;
            return _root == null || _root.Check(out count);
        }

        private Node Minimum(Node node)
        {
            var result = node;
            while (result.Left != null) result = result.Left;
            return result;
        }

        private Node Maximum(Node node)
        {
            var result = node;
            while (result.Right != null) result = result.Right;
            return result;
        }

        private Node Next(Node node)
        {
            Node result;
            if (node.Right != null)
            {
                result = Minimum(node.Right);
            }
            else
            {
                while (node.Parent != null && node.Parent.Right == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        private Node Previous(Node node)
        {
            Node result;
            if (node.Left != null)
            {
                result = Maximum(node.Left);
            }
            else
            {
                while (node.Parent != null && node.Parent.Left == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        public void Print()
        {
            var node = Minimum(_root);
            while (node != null)
            {
                Console.Write(node.Red ? '*' : ' ');
                Console.Write(node.Key);
                Console.Write('\t');
                node = Next(node);
            }
        }

        #region Nested classes

        [DebuggerDisplay("{ToString()}")]
        private sealed class Node
        {
            public TKey Key;
            public TValue Value;
            public bool Red;

            public Node Parent;
            public Node Left;
            public Node Right;

            public bool Check(out int count)
            {
                count = 0;
                if (Red)
                {
                    if (Left != null && Left.Red) return false;
                    if (Right != null && Right.Red) return false;
                }
                var left = 0;
                var right = 0;
                if (Left != null && !Left.Check(out left)) return false;
                if (Right != null && !Right.Check(out right)) return false;
                count = left + (Red ? 0 : 1);
                if (left != right)
                {
                    ;
                }
                return left == right;
            }

            public override string ToString()
            {
                return ToShortString(2);
            }

            private string ToShortString(int depth = 0)
            {
                return depth == 0
                    ? string.Format("{0}{1}", Red ? "*" : "", Key)
                    : string.Format("({1}<{0}>{2})", ToShortString(), Left == null ? "null" : Left.ToShortString(depth - 1), Right == null ? "null" : Right.ToShortString(depth - 1));
            }
        }

        #endregion

        #region IEnumerable

        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
        {
            throw new NotImplementedException();
        }

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

        #endregion
    }
}

namespace Codeforces.TaskC
{
    public class Task
    {
        public static void Main()
        {
            var task = new Task();
            try
            {
                task.Solve();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
                throw;
            }
        }

        /*abacabadabacaba*/

        private long MaxSubstring(long best, long l, long r, long a, long b, int ch)
        {
            if (l > r || a > b) return best;
            if ((best >= b - a + 1) || (best >= r - l + 1)) return best;

            best = Math.Max(best, Math.Min(r, b) - Math.Max(l, a) + 1);
            var divide = 1 << ch;
             bool f1 = false, f2 = false;

            if (r == divide && l == r) return best;
            if (a == divide && a == b) return best;

            if (l == divide) l++;
            if (r == divide) r--;
            if (a == divide) a++;
            if (b == divide) b--;

            if (l > divide)
            {
                l -= divide;
                f1 = true;
            }
            if (r > divide)
            {
                r -= divide;
                f1 = !f1;
            }
            if (a > divide)
            {
                a -= divide;
                f2 = true;
            }
            if (b > divide)
            {
                b -= divide;
                f2 = !f2;
            }

            if (--ch > 0)
            {
                if (f1 && f2) best = Math.Max(Math.Max(best, divide - Math.Max(l, a)), Math.Min(r, b));
                if (f1 && !f2)
                {
                    best = MaxSubstring(best, l, divide - 1, a, b, ch);
                    best = MaxSubstring(best, 1, r, a, b, ch);
                }
                if (!f1 && f2)
                {
                    best = MaxSubstring(best, l, r, a, divide - 1, ch);
                    best = MaxSubstring(best, l, r, 1, b, ch);
                }
                if (!f1 && !f2) best = MaxSubstring(best, l, r, a, b, ch);
                if (f1 && f2)
                {
                    best = MaxSubstring(best, 1, r, a, divide - 1, ch);
                    best = MaxSubstring(best, l, divide - 1, 1, b, ch);
                }
            }

            return best;
        }

        void Solve()
        {
            long l1, r1, l2, r2;
            Input.Next(out l1, out r1, out l2, out r2);
            var n = MaxSubstring(0, l1, r1, l2, r2, 29);
            Console.WriteLine(n);
        }
    }
}


using System;

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

namespace Codeforces
{
    public class Input
    {
        private static string _line;

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

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

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

            return ok;
        }

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

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

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

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

        public static bool Next(out string value)
        {
            value = string.Empty;
            if (!Next()) return false;
            value = _line;
            return true;
        }
    }

    public class DisjointSet
    {
        private readonly int[] _parent;
        private readonly int[] _rank;
        public int Count { get; private set; }

        public DisjointSet(int count, int initialize = 0)
        {
            Count = count;
            _parent = new int[Count];
            _rank = new int[Count];
            for (var i = 0; i < initialize; i++) _parent[i] = i;
        }

        private DisjointSet(int count, int[] parent, int[] rank)
        {
            Count = count;
            _parent = parent;
            _rank = rank;
        }

        public void Add(int v)
        {
            _parent[v] = v;
            _rank[v] = 0;
        }

        public int Find_Recursive(int v)
        {
            if (_parent[v] == v) return v;
            return _parent[v] = Find(_parent[v]);
        }

        public int Find(int v)
        {
            if (_parent[v] == v) return v;
            var last = v;
            while (_parent[last] != last) last = _parent[last];
            while (_parent[v] != v)
            {
                var t = _parent[v];
                _parent[v] = last;
                v = t;
            }
            return last;
        }

        public int this[int v]
        {
            get { return Find(v); }
            set { Union(v, value); }
        }

        public void Union(int a, int b)
        {
            a = Find(a);
            b = Find(b);
            if (a == b) return;
            if (_rank[a] < _rank[b])
            {
                var t = _rank[a];
                _rank[a] = _rank[b];
                _rank[b] = t;
            }
            _parent[b] = a;
            if (_rank[a] == _rank[b]) _rank[a]++;
        }

        public int GetSetCount()
        {
            var result = 0;
            for (var i = 0; i < Count; i++)
            {
                if (_parent[i] == i) result++;
            }
            return result;
        }

        public DisjointSet Clone()
        {
            var rank = new int[Count];
            _rank.CopyTo(rank, 0);
            var parent = new int[Count];
            _parent.CopyTo(parent, 0);
            return new DisjointSet(Count, parent, rank);
        }

        public override string ToString()
        {
            return string.Join(",", _parent.Take(50));
        }
    }

    public class Matrix
    {
        public static Matrix Create(int i, int j)
        {
            var m = new Matrix(i, j);
            return m;
        }

        public static Matrix Create(int i)
        {
            var m = new Matrix(i, i);
            return m;
        }

        public long Modulo { get; set; }

        private readonly int _width;
        private readonly int _height;
        private readonly long[,] _data;
        public int Width{get { return _width; }}
        public int Height{get { return _height; }}

        private Matrix(int i, int j)
        {
            Modulo = 1000000000000000000L;
            _width = j;
            _height = i;
            _data = new long[_height, _width];
        }

        public static Matrix operator *(Matrix m1, Matrix m2)
        {
            if (m1.Width != m2.Height) throw new InvalidDataException("m1.Width != m2.Height");
            var m = Create(m2.Width, m1.Height);
            m.Modulo = m1.Modulo;
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                {
                    for (var k = 0; k < m1.Width; k++)
                        m[j, i] += (m1[j, k]*m2[k, i]) % m1.Modulo;
                    m[j, i] %= m1.Modulo;
                }
            return m;
        }

        public static Matrix operator +(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] + m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator -(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] - m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator *(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i=0;i<m1.Width;i++)
                for (var j=0;j<m1.Height;j++)
                        m[j, i] = (m[j, i] * l) % m.Modulo;
            return m;
        }

        public static Matrix operator *(long l, Matrix m1)
        {
            return m1*l;
        }

        public static Matrix operator +(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i = 0; i < m1.Width; i++)
                    m[i, i] = (m[i, i] + l) % m.Modulo;
            return m;
        }

        public static Matrix operator +(long l, Matrix m1)
        {
            return m1 + l;
        }

        public static Matrix operator -(Matrix m1, long l)
        {
            return m1 + (-l);
        }

        public static Matrix operator -(long l, Matrix m1)
        {
            var m = m1.Clone() * -1;
            return m + l;
        }

        public Matrix BinPower(long l)
        {
            var n = 1;
            var m = Clone();
            var result = new Matrix(m.Height, m.Width) + 1;
            result.Modulo = m.Modulo;
            while (l != 0)
            {
                var i = l & ~(l - 1);
                l -= i;
                while (n < i)
                {
                    m = m*m;
                    n <<= 1;
                }
                result *= m;
            }
            return result;
        }

        public void Fill(long l)
        {
            l %= Modulo;
            for (var i = 0; i < _height; i++)
                for (var j = 0; j < _width; j++)
                    _data[i, j] = l;
        }

        public Matrix Clone()
        {
            var m = new Matrix(_width, _height);
            Array.Copy(_data, m._data, _data.Length);
            m.Modulo = Modulo;
            return m;
        }

        public long this[int i, int j]
        {
            get { return _data[i, j]; }
            set { _data[i, j] = value % Modulo; }
        }
    }

    public class RedBlackTree<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
    {
        private readonly List<Node> _items = new List<Node>();
        private Node _root;
        private readonly IComparer<TKey> _comparer;

        public RedBlackTree()
        {
            _comparer = Comparer<TKey>.Default;
        }

        private Node _search(TKey key)
        {
            var node = _root;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return node;
                node = i > 0 ? node.Right : node.Left;
            }
            return null;
        }

        public void Add(TKey key, TValue value)
        {
            var node = new Node { Key = key, Value = value, Red = true };
            _items.Add(node);
            if (_root == null)
            {
                _root = node;
                _root.Red = false;
                return;
            }
            var x = _root;
            Node y = null;
            while (x != null)
            {
                y = x;
                x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;
            }
            node.Parent = y;
            if (y == null) _root = node;
            else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;
            else y.Left = node;
            InsertFixup(node);
        }

        private void InsertFixup(Node node)
        {
            while (true)
            {
                var parent = node.Parent;
                if (parent == null || !parent.Red || parent.Parent == null) break;
                var grand = parent.Parent;

                if (parent == grand.Left)
                {
                    var uncle = grand.Right;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Right) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateLeft(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateRight(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
                else
                {
                    if (_root.Parent != null) Debugger.Break();

                    var uncle = grand.Left;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Left) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateRight(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateLeft(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
            }
            _root.Red = false;
        }

        private void RotateLeft(Node node)
        {
            if (node.Right == null)
                throw new NotSupportedException("Cannot rotate left: right node is missing");
            var parent = node.Parent;
            var right = node.Right;
            right.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = right;
                else parent.Right = right;
            }
            node.Right = right.Left;
            if (node.Right != null)
                node.Right.Parent = node;
            right.Left = node;
            node.Parent = right;
        }

        private void RotateRight(Node node)
        {
            if (node.Left == null)
                throw new NotSupportedException("Cannot rotate right: left node is missing");
            var parent = node.Parent;
            var left = node.Left;
            left.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = left;
                else parent.Right = left;
            }
            node.Left = left.Right;
            if (node.Left != null)
                node.Left.Parent = node;
            left.Right = node;
            node.Parent = left;
        }

        public void Remove(TKey key)
        {
            var node = _search(key);
            if (node == null) return;

            var deleted = node.Left == null || node.Right == null ? node : Next(node);
            var child = deleted.Left ?? deleted.Right;
            if (child != null)
                child.Parent = deleted.Parent;
            if (deleted.Parent == null) /* root */
                _root = child;
            else if (deleted == deleted.Parent.Left)
                deleted.Parent.Left = child;
            else
                deleted.Parent.Right = child;
            if (node != deleted)
            {
                node.Key = deleted.Key;
                node.Value = deleted.Value;
            }

            if (!deleted.Red)
            {
                DeleteFixup(child, deleted.Parent);
            }
        }

        private void DeleteFixup(Node node, Node parent)
        {
            while (parent != null && (node == null || !node.Red))
            {
                if (node == parent.Left)
                {
                    var brother = parent.Right;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateLeft(parent);
                        brother = parent.Right;
                    }
                    if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Right == null || !brother.Right.Red)
                        {
                            if (brother.Left != null)
                                brother.Left.Red = false;
                            brother.Red = true;
                            RotateRight(brother);
                            brother = parent.Right;
                        }
                        if (!brother.Right.Red) Debugger.Break();
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Right != null)
                            brother.Right.Red = false;
                        RotateLeft(parent);
                        node = _root;
                    }
                }
                else
                {
                    var brother = parent.Left;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateRight(parent);
                        brother = parent.Left;
                    }
                    if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Left == null || !brother.Left.Red)
                        {
                            if (brother.Right != null)
                                brother.Right.Red = false;
                            brother.Red = true;
                            RotateLeft(brother);
                            brother = parent.Left;
                        }
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Left != null)
                            brother.Left.Red = false;
                        RotateRight(parent);
                        node = _root;
                    }
                }
                parent = node.Parent;
            }

            node.Red = false;
        }

        public TValue this[TKey key]
        {
            get
            {
                var node = _search(key);
                return node == null ? default(TValue) : node.Value;
            }
            set
            {
                var node = _search(key);
                if (node == null) Add(key, value);
                else node.Value = value;
            }
        }

        public bool Check()
        {
            int count;
            return _root == null || _root.Check(out count);
        }

        private Node Minimum(Node node)
        {
            var result = node;
            while (result.Left != null) result = result.Left;
            return result;
        }

        private Node Maximum(Node node)
        {
            var result = node;
            while (result.Right != null) result = result.Right;
            return result;
        }

        private Node Next(Node node)
        {
            Node result;
            if (node.Right != null)
            {
                result = Minimum(node.Right);
            }
            else
            {
                while (node.Parent != null && node.Parent.Right == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        private Node Previous(Node node)
        {
            Node result;
            if (node.Left != null)
            {
                result = Maximum(node.Left);
            }
            else
            {
                while (node.Parent != null && node.Parent.Left == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        public void Print()
        {
            var node = Minimum(_root);
            while (node != null)
            {
                Console.Write(node.Red ? '*' : ' ');
                Console.Write(node.Key);
                Console.Write('\t');
                node = Next(node);
            }
        }

        #region Nested classes

        [DebuggerDisplay("{ToString()}")]
        private sealed class Node
        {
            public TKey Key;
            public TValue Value;
            public bool Red;

            public Node Parent;
            public Node Left;
            public Node Right;

            public bool Check(out int count)
            {
                count = 0;
                if (Red)
                {
                    if (Left != null && Left.Red) return false;
                    if (Right != null && Right.Red) return false;
                }
                var left = 0;
                var right = 0;
                if (Left != null && !Left.Check(out left)) return false;
                if (Right != null && !Right.Check(out right)) return false;
                count = left + (Red ? 0 : 1);
                if (left != right)
                {
                    ;
                }
                return left == right;
            }

            public override string ToString()
            {
                return ToShortString(2);
            }

            private string ToShortString(int depth = 0)
            {
                return depth == 0
                    ? string.Format("{0}{1}", Red ? "*" : "", Key)
                    : string.Format("({1}<{0}>{2})", ToShortString(), Left == null ? "null" : Left.ToShortString(depth - 1), Right == null ? "null" : Right.ToShortString(depth - 1));
            }
        }

        #endregion

        #region IEnumerable

        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
        {
            throw new NotImplementedException();
        }

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

        #endregion
    }
}

namespace Codeforces.TaskC
{
    public class Task
    {
        public static void Main()
        {
            var task = new Task();
            try
            {
                task.Solve();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
                throw;
            }
        }

        /*abacabadabacaba*/

        private long MaxSubstring(long best, long l, long r, long a, long b, int ch)
        {
            if (l > r || a > b) return best;
            if ((best >= b - a + 1) || (best >= r - l + 1)) return best;

            best = Math.Max(best, Math.Min(r, b) - Math.Max(l, a) + 1);
            var divide = 1 << ch;
             bool f1 = false, f2 = false;

            if (r == divide && l == r) return best;
            if (a == divide && a == b) return best;

            if (l == divide) l++;
            if (r == divide) r--;
            if (a == divide) a++;
            if (b == divide) b--;

            if (l > divide)
            {
                l -= divide;
                f1 = true;
            }
            if (r > divide)
            {
                r -= divide;
                f1 = !f1;
            }
            if (a > divide)
            {
                a -= divide;
                f2 = true;
            }
            if (b > divide)
            {
                b -= divide;
                f2 = !f2;
            }

            if (--ch >= 0)
            {
                if (f1 && f2) best = Math.Max(Math.Max(best, divide - Math.Max(l, a)), Math.Min(r, b));
                if (f1 && !f2)
                {
                    best = MaxSubstring(best, l, divide - 1, a, b, ch);
                    best = MaxSubstring(best, 1, r, a, b, ch);
                }
                if (!f1 && f2)
                {
                    best = MaxSubstring(best, l, r, a, divide - 1, ch);
                    best = MaxSubstring(best, l, r, 1, b, ch);
                }
                if (!f1 && !f2) best = MaxSubstring(best, l, r, a, b, ch);
                if (f1 && f2)
                {
                    best = MaxSubstring(best, 1, r, a, divide - 1, ch);
                    best = MaxSubstring(best, l, divide - 1, 1, b, ch);
                }
            }

            return best;
        }

        void Solve()
        {
            long l1, r1, l2, r2;
            Input.Next(out l1, out r1, out l2, out r2);
            var n = MaxSubstring(0, l1, r1, l2, r2, 29);
            Console.WriteLine(n);
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    const int MOD = 1000003;

    long[,] MatMult(long[,] a, long[,] b, int n)
    {
        var ret = new long[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++)
                    ret[i, j] = (ret[i, j] + a[i, k] * b[k, j]) % MOD;
        return ret;
    }

    long[,] MatPow(long[,] a, int n, int p)
    {
        var ret = new long[n, n];
        for (int i = 0; i < n; i++)
            ret[i, i] = 1;
        while (p > 0)
        {
            if ((p & 1) == 1)
                ret = MatMult(ret, a, n);
            a = MatMult(a, a, n);
            p >>= 1;
        }
        return ret;
    }

    public void Solve()
    {
        int n = ReadInt();
        int w = ReadInt();
        int h = ReadInt();

        var a = new long[w + 1, w + 1];
        for (int i = 0; i <= w; i++)
            a[0, i] = 1;
        for (int i = 1; i <= w; i++)
            a[i, i - 1] = h;

        a = MatPow(a, w + 1, n);
        long ans = 0;
        for (int i = 0; i <= w; i++)
            ans += a[i, 0];

        Write(ans % MOD);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput(),Encoding.ASCII);
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
using System.Numerics;

class Solution
{
     public class GCD
    {
		public static int Euclidean(int n1, int n2)
		{
			if (n1 == n2) return n1;
			else if (n1 < n2)
			{
				var tmp = n1;
				n1 = n2;
				n2 = tmp;
			}

			while (n1 % n2 > 0)
			{
				var tmp = n2;
				n2 = n1 % n2;
				n1 = tmp;
			}
			return n2;
		}
        public static ulong Euclidean(ulong n1, ulong n2)
		{
			if (n1 == n2) return n1;
			else if (n1 < n2)
			{
				var tmp = n1;
				n1 = n2;
				n2 = tmp;
			}

			while (n1 % n2 > 0)
			{
				var tmp = n2;
				n2 = n1 % n2;
				n1 = tmp;
			}
			return n2;
		}

          public static long Inverse(long a, long n)
		{
            long x, y =0;
            EuclideanExt(a, n, out x, out y);
            return x<0?n+x:x;
        }

        public static long EuclideanExt(long n1, long n2, out long x, out long y)
		{
            x = 0;
            y = 1;

            bool r = false;
			if (n1 == n2) return n1;

			else if (n1 < n2)
			{
                r = true;
				var tmp = n1;
				n1 = n2;
				n2 = tmp;
			}
            long q = 0;
            long xl =1;
            long yl = 0;

			while (n2 > 0)
			{
                q = n1 / n2;

				var tmp = n2;
				n2 = n1 % n2;
				n1 = tmp;

                tmp = x;
                x = xl - q *x;
                xl = tmp ;

                tmp = y;
                y = yl - q*y;
                yl = tmp;

			}
            x = xl;
            y = yl;
            if (r)
            {
                x =yl;
                y =xl;
            }
			return x*n1+y*n2;
		}
	}
    static Tuple<ulong, ulong> sum(Tuple<ulong, ulong> a, Tuple<ulong, ulong> b)
    {
        if (a.Item1 == 0)
            return b;
        if(b.Item1 == 0)
            return a;
        return Tuple.Create(
            ((a.Item1 * b.Item2) % mod + (b.Item1 * a.Item2) % mod) % mod,
            (a.Item2 * b.Item2) % mod
        );
    }

    static Tuple<ulong, ulong> prod(Tuple<ulong, ulong> a, Tuple<uint, uint> b)
    {
        return Tuple.Create(
            (a.Item1 * b.Item1) %mod,
            (a.Item2 * b.Item2) % mod
        );
    }

    static Tuple<uint, uint> PInOneSide(uint cnt, uint totalcnt)
    {
        return Tuple.Create(
            cnt * (cnt - 1) + (totalcnt - cnt) * (totalcnt - cnt - 1),
            totalcnt * (totalcnt - 1)
        );
    }

    static Tuple<uint, uint> PIncreaseLeftA(uint leftCnt, uint leftACnt, uint totalcnt)
    {
        return Tuple.Create(
             (leftCnt - leftACnt) * (leftCnt - leftACnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    static Tuple<uint, uint> PDecreaseLeftA(uint leftCnt, uint leftACnt, uint totalcnt)
    {
        return Tuple.Create(
            leftACnt * (totalcnt - 2 * leftCnt + leftACnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    static Tuple<uint, uint> PSameInBothSide(uint leftCnt, uint leftACnt, uint totalcnt)
    {
        return Tuple.Create(
             (leftCnt - leftACnt) * (totalcnt + 2 * leftACnt - 2 * leftCnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    const ulong mod = 1000000007L;
    static void Main(string[] args)
    {

        // var n = int.Parse( Console.ReadLine());
        var tmp = Array.ConvertAll(Console.ReadLine().Trim().Split(), Convert.ToUInt64);
        var n = (uint)tmp[0];
        var k = tmp[1];

        var arr = Array.ConvertAll(Console.ReadLine().Trim().Split(), Convert.ToByte);

        var leftcnt = (uint)arr.Count(el=>el==0);
        var leftAcnt = (uint)arr.Where((el, i)=>el == 0 && i<leftcnt ).Count();
        if (k < (leftcnt - leftAcnt))
        {
            Console.WriteLine("0");
            return;
        }
        if (leftcnt == n)
        {
            Console.WriteLine("1");
            return;
        }

        var lowerBnd = Math.Max((uint)0, 2*leftcnt - n);
        Tuple<ulong, ulong>[] F =Enumerable.Repeat(0, (int)(leftcnt - lowerBnd+1))
        .Select(el =>new Tuple<ulong,ulong>(0, 0)).ToArray();

        F[leftAcnt - lowerBnd] = Tuple.Create(1ul,1ul);
        for(ulong j = 0; j < k; j++)
        {
            Tuple<ulong, ulong>[] Ftmp = new Tuple<ulong, ulong>[leftcnt - lowerBnd+1];

            for(uint i =0; i <= leftcnt - lowerBnd; i++)
            {

                var res = prod(F[i], PInOneSide(leftcnt, n));
                res = sum(res,prod(F[i], PSameInBothSide(leftcnt, i+lowerBnd , n)));
                if (i > 0)
                    res = sum(res,prod(F[i - 1], PIncreaseLeftA(leftcnt, i+lowerBnd -1 , n)));
                if (i < leftcnt - lowerBnd)
                    res = sum(res,prod(F[i + 1], PDecreaseLeftA(leftcnt, i+lowerBnd + 1 , n)));
                Ftmp[i] = res;
            }
            F = Ftmp;
        }
        var gcd = GCD.Euclidean(F.Last().Item1, F.Last().Item2);
        var ret = Tuple.Create(F.Last().Item1 / gcd, F.Last().Item2 / gcd);

        var ret2 = ((long)ret.Item1 * GCD.Inverse((long)ret.Item2, (long)mod )) % (long)mod;

        Console.WriteLine($"{ret2}");

    }
}


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            const long MOD = 1000000000 + 7;

            int n = ReadInt();
            long k = ReadLong();
            int[] a = ReadIntArray();

            int m = a.Sum();

            if (m == n)
            {
                Writer.WriteLine(1);
                return;
            }

            long[,] b = new long[m + 1, m + 1];
            for (int i = 0; i < m + 1; i++)
            {
                long l = Math.Max(0, 2 * i * (n + i - 2 * m));
                long r = 2 * (m - i) * (m - i);
                long e = n * (n - 1) - l - r;
                long inv = Inv(n * (n - 1), MOD);
                if (l > 0)
                {
                    b[i, i - 1] = l * inv % MOD;
                }
                b[i, i] = e * inv % MOD;
                if (r > 0)
                {
                    b[i, i + 1] = r * inv % MOD;
                }
            }

            long[,] c = MatrixBinPower(m + 1, b, k, MOD);

            int st = 0;
            for (int i = 0; i < m; i++)
            {
                st += a[n - i - 1];
            }

            long ans = c[st, m];

            Writer.WriteLine(ans);
        }

        public static long Inv(long a, long mod)
        {
            return BinPower(a, mod - 2, mod);
        }

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

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

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

            return result;
        }

        public static long[,] MatrixBinPower(int n, long[,] a, long p, long mod)
        {
            long[,] result = new long[n, n];
            for (int i = 0; i < n; i++)
            {
                result[i, i] = 1;
            }

            while (p > 0)
            {
                if ((p & 1) != 0)
                {
                    result = MatrixMult(n, result, a, mod);
                }

                a = MatrixMult(n, a, a, mod);
                p >>= 1;
            }

            return result;
        }

        public static long[,] MatrixMult(int n, long[,] a, long[,] b, long mod)
        {
            long[,] c = new long[n, n];

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

            return c;
        }

        public static void Solve()
        {
#if DEBUG
            var sw = Stopwatch.StartNew();
#endif

            SolveCase();

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                Writer.Write("Case #{0}: ", 1 - t);
                SolveCase();
            }*/

#if DEBUG
            sw.Stop();
            Console.WriteLine($"{sw.ElapsedMilliseconds} ms");
#endif
        }

        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            // Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            // Solve();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Shuffle(result);
            return result;
        }

        private static void Shuffle<T>(IList<T> array)
        {
            Random rnd = new Random();
            for (int i = array.Count - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = array[k];
                array[k] = array[i];
                array[i] = tmp;
            }
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        private static Queue<string> CurrentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (CurrentLineTokens.Count == 0)
                CurrentLineTokens = new Queue<string>(ReadAndSplitLine());
            return CurrentLineTokens.Dequeue();
        }

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

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++)
                lines[i] = Reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            Writer.WriteLine(string.Join(" ", array));
        }

        #endregion
    }
}


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

class Myon
{
    public Myon() { }
    static void Main(string[] args)
    {
        new Myon().calc();
    }

    void calc()
    {
        string[] board = new string[8];
        for (int i = 0; i < 8; i++)
        {
            board[i] = Console.ReadLine();
        }
        if (calc2(board)) Console.WriteLine("WIN");
        else Console.WriteLine("LOSE");
    }

    bool calc2(string[] board)
    {
        bool[,] now = new bool[8, 8];
        now[7, 0] = true;
        for (int turn = 0; turn < 30; turn++)
        {
            bool[,] next = new bool[8, 8];
            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 8; x++)
                {
                    if (y - turn >= 0 && board[y - turn][x] == 'S') continue;
                    if (y - (turn + 1) >= 0 && board[y - (turn + 1)][x] == 'S') continue;
                    for (int vy = -1; vy <= 1; vy++)
                    {
                        for (int vx = -1; vx <= 1; vx++)
                        {
                            int ny = y + vy;
                            int nx = x + vx;
                            if (ok(ny, nx) && now[ny, nx])
                            {
                                next[y, x] = true;
                                if (board[y][x] == 'A') return true;
                            }
                        }
                    }
                }
            }
            now = next;
        }
        return false;
    }

    bool ok(int y, int x)
    {
        return x >= 0 && y >= 0 && x < 8 && y < 8;
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private const string Test = "C4";

        class Pair
        {
            public int X;
            public int Y;
        }

        private static List<Pair> stats;
        private static int[] direct;
        private static void Solve()
        {
            stats = new List<Pair>();
            for (int i = 0; i < 8; i++)
            {
                var input = Read();
                for (int j = 0; j < 8; j++)
                {
                    if(input[j] == 'S')
                    {
                        stats.Add(new Pair {X = i, Y = j});
                    }
                }
            }
            direct = new[] {-1, 0, 1};
            if(CanMove(7, 0, 0))
                Console.WriteLine("WIN");
            else
            {
                Console.WriteLine("LOSE");
            }
        }

        private static bool CanMove(int x, int y, int step)
        {
            if(step >= 9)
                return true;
            if(x > 7 || y < 0)
            {
                return false;
            }
            if(stats.Any(s=>s.Y == y && (s.X + step == x || s.X + step - 1 == x)))
                return false;

            foreach (var dX in direct)
            {
                foreach (var dY in direct)
                {
                    if (CanMove(x + dX, y + dY, step + 1))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(String.Format(@"..\..\..\..\Tests\{0}.in", Test)));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        #region Reader

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

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

        private static int[] ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}