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

namespace ProgrammingContest.Codeforces.Round59
{
    class C
    {
        int n;
        int[][] dat;
        int count;
        int res;
        int[] xs = new int[4];

        bool ok(int[] data)
        {
            int a = 0, b = 0;
            int[] pos = new int[10];
            for (int i = 0; i < 10; i++)
                pos[i] = -1;
            for (int i = 0; i < 4; i++)
                pos[xs[i]] = i;
            for (int m = data[0], i = 3; i >= 0; i--, m /= 10)
            {
                if (pos[m % 10] == i) a++;
                else if (pos[m % 10] >= 0) b++;
            }

            return a == data[1] && b == data[2];
        }

        void dfs(int idx)
        {
            if (idx >= 4)
            {
                if (dat.All(d => ok(d)))
                {
                    res = xs[0] * 1000 + xs[1] * 100 + xs[2] * 10 + xs[3];
                    count++;
                }
                return;
            }

            for (int i = 0; i < 10; i++)
            {
                if (xs.Take(idx).All(x => x != i))
                {
                    xs[idx] = i;
                    dfs(idx + 1);
                }
            }
        }

        C()
        {
            n = int.Parse(Console.ReadLine());
            dat = new int[n][];
            for (int i = 0; i < n; i++)
                dat[i] = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));

            xs = new int[4];
            dfs(0);

            Console.WriteLine(
                count == 0 ? "Incorrect data" :
                (count != 1 ? "Need more data" : res.ToString("0000")));
        }

        public static void Main()
        {
            new C();
        }
    }
}


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

public class Program
{
    int N, K;
    int[] A;
    int Ans = int.MaxValue;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        A = sc.IntArray();
        var ls = A.ToList();
        ls.Sort();
        DFS(ls, 1);
        Console.WriteLine(Ans);
    }

    void DFS(List<int> L, int i)
    {
        if (L.Count < K) return;
        int[] cnt = new int[L.Count];
        for (int j = 0; j < L.Count; j++)
        {
            int c = 0;
            int tmp = L[j];
            while (tmp > 0)
            {
                c++;
                tmp /= 2;
            }
            cnt[j] = c;
        }
        {
            int cost = 0;
            for (int j = 0; j < K; j++)
            {
                cost += cnt[j] - i;
            }
            Ans = Math.Min(Ans, cost);
        }
        // i桁以上は一致している
        // 上位i桁を見る
        // 0のやつ1のやつに振り分ける

        List<int> zero = new List<int>();
        List<int> one = new List<int>();
        for (int j = 0; j < L.Count; j++)
        {
            int ll = cnt[j] - i - 1;
            if (ll < 0) continue;
            if ((L[j] & (1 << ll)) == 0) zero.Add(L[j]);
            else one.Add(L[j]);
        }
        DFS(zero, i + 1);
        DFS(one, i + 1);
    }

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

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

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

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

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

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

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

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


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

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

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static int Solve(string[] args)
        {
            int n = Next();
            int k = Next();

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

            var head = new Leaf();

            foreach (int i in nn)
            {
                var st = new Stack<int>();
                int ii = i;
                while (ii > 0)
                {
                    st.Push(ii & 1);
                    ii >>= 1;
                }

                Leaf c = head;
                c.count++;
                while (st.Count > 0)
                {
                    if (c.count <= k)
                    {
                        c.cost += st.Count;
                    }
                    int p = st.Pop();
                    if (p == 0)
                    {
                        if (c.l == null)
                            c.l = new Leaf();
                        c = c.l;
                    }
                    else
                    {
                        if (c.r == null)
                            c.r = new Leaf();
                        c = c.r;
                    }
                    c.count++;
                }
            }
            int min = head.cost;
            var q = new Queue<Leaf>();
            q.Enqueue(head);
            while (q.Count > 0)
            {
                Leaf t = q.Dequeue();
                if (t.l != null && t.l.count >= k)
                {
                    min = Math.Min(min, t.l.cost);
                    q.Enqueue(t.l);
                }
                if (t.r != null && t.r.count >= k)
                {
                    min = Math.Min(min, t.r.cost);
                    q.Enqueue(t.r);
                }
            }
            return min;
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }

        #region Nested type: Leaf

        private class Leaf
        {
            public int cost;
            public int count;
            public Leaf l, r;
        }

        #endregion
    }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    private const int MAX = 500000;

    public void Solve()
    {
        int n = ReadInt();
        int d = ReadInt();
        var a = ReadIntArray();

        var dp = new bool[MAX + 1];
        dp[0] = true;
        for (int i = 0; i < n; i++)
        {
            for (int j = MAX; j >= 0; j--)
                if (dp[j])
                    dp[j + a[i]] = true;
        }

        int x = 0;
        int ans = 0;
        while (true)
        {
            int y = Math.Min(x + d, MAX);
            while (!dp[y])
                y--;
            if (x == y)
                break;
            ans++;
            x = y;
        }

        Write(x, ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("subsequences.in");
        //writer = new StreamWriter("subsequences.out");
#endif
        try
        {
//            var thread = new Thread(new Solver().Solve, 1024 * 1024 * 256);
//            thread.Start();
//            thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            Console.WriteLine(ex);
            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);
    }

    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; }
        }
    }

    #endregion
}


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

namespace CF
{
	class _364B
	{
		private const int KMaxPrice = 10000;

		private static void Main(String[] args)
		{
			var parts = Console.ReadLine().Split(' ');
			int n = int.Parse(parts[0]),
				d = int.Parse(parts[1]);
			int[] a = new int[n];
			parts = Console.ReadLine().Split(' ');
			for (int i = 0; i < n; i++)
				a[i] = int.Parse(parts[i]);
			int limit = KMaxPrice*n;
			int[,] map = new int[limit + 1, n + 1];
			map[0, 0] = 1;
			for (int i = 0; i < n; ++i)
				for (int j = limit; j >= 0; --j)
					if (map[j, i] != 0)
					{
						map[j + a[i], i + 1] = 1;
						map[j, i + 1] = 1;
					}
			int ans = 0, days = 0;
			while (ans < limit)
			{
				int eat = 0;
				for (int j = 0; j <= d; ++j)
					if (ans + j <= limit
						&& map[ans + j, n] != 0)
						eat = j;
				if (0 == eat)
					break;
				//Console.WriteLine("{0} {1}", eat, days);
				ans += eat;
				++days;
			}
			Console.WriteLine("{0} {1}", ans, days);
		}
	}
}


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

namespace TechnoCup2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] layer1 = Console.ReadLine().Split(' ');
            string[] layer2 = Console.ReadLine().Split(' ');
            string[] layer3 = Console.ReadLine().Split(' ');
            Console.ReadLine();
            string[] layer4 = Console.ReadLine().Split(' ');
            string[] layer5 = Console.ReadLine().Split(' ');
            string[] layer6 = Console.ReadLine().Split(' ');
            Console.ReadLine();
            string[] layer7 = Console.ReadLine().Split(' ');
            string[] layer8 = Console.ReadLine().Split(' ');
            string[] layer9 = Console.ReadLine().Split(' ');
            string[] coordinates = Console.ReadLine().Split(' ');
            BigField bigField = new BigField();
            bigField.fields[0, 0] = new Field(layer1[0], layer2[0], layer3[0]);
            bigField.fields[1, 0] = new Field(layer1[1], layer2[1], layer3[1]);
            bigField.fields[2, 0] = new Field(layer1[2], layer2[2], layer3[2]);

            bigField.fields[0, 1] = new Field(layer4[0], layer5[0], layer6[0]);
            bigField.fields[1, 1] = new Field(layer4[1], layer5[1], layer6[1]);
            bigField.fields[2, 1] = new Field(layer4[2], layer5[2], layer6[2]);

            bigField.fields[0, 2] = new Field(layer7[0], layer8[0], layer9[0]);
            bigField.fields[1, 2] = new Field(layer7[1], layer8[1], layer9[1]);
            bigField.fields[2, 2] = new Field(layer7[2], layer8[2], layer9[2]);

            int[] coordinatesNumeric = new int[] { Convert.ToInt32(coordinates[1]), Convert.ToInt32(coordinates[0]) };
            int[] coordinatesInternal = new int[] { coordinatesNumeric[0] % 3, coordinatesNumeric[1] % 3 };
            if (coordinatesInternal[0] == 0)
                coordinatesInternal[0] = 3;
            if (coordinatesInternal[1] == 0)
                coordinatesInternal[1] = 3;

            //int[] coordinatesExternal = new int[] { (coordinatesNumeric[0] - coordinatesInternal[0]) / 3, (coordinatesNumeric[1] - coordinatesInternal[1]) / 3 };

            if (bigField.fields[coordinatesInternal[0] - 1, coordinatesInternal[1] - 1].isFullBusy)
            {
                bigField.SetFullEmpty();
            }
            else
            {
                bigField.fields[coordinatesInternal[0] - 1, coordinatesInternal[1] - 1].SetEmpty();
            }
            for(int i = 0; i < 9; i++)
            {
                if (i % 3 == 0 && i != 0)
                    Console.WriteLine();
                Console.WriteLine(bigField.printLayer(i));
            }
            //Console.ReadKey();
        }
    }
    class Field
    {
        public int[,] busy;
        public Field(string layer1, string layer2, string layer3)
        {
            fill(layer1, layer2, layer3);
        }
        public void fill(string layer1, string layer2, string layer3)
        {
            busy = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                if (layer1[i] == 'o')
                    busy[i, 0] = 1;
                if (layer2[i] == 'o')
                    busy[i, 1] = 1;
                if (layer3[i] == 'o')
                    busy[i, 2] = 1;

                if (layer1[i] == 'x')
                    busy[i, 0] = 2;
                if (layer2[i] == 'x')
                    busy[i, 1] = 2;
                if (layer3[i] == 'x')
                    busy[i, 2] = 2;
            }
        }
        public bool isFullBusy { get
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                        if (busy[i, j] == 0)
                            return false;
                }
                return true;
            }
        }
        public void SetEmpty()
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                    if (busy[i, j] == 0)
                        busy[i, j] = 3;
            }
        }
        public string printLayer(int layerNum)
        {
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < 3; i++)
            {
                switch(busy[i, layerNum])
                {
                    case 1:
                        sb.Append("o");
                        break;
                    case 2:
                        sb.Append("x");
                        break;
                    case 3:
                        sb.Append("!");
                        break;
                    default:
                        sb.Append(".");
                        break;
                }
            }
            return sb.ToString();
        }

    }
    class BigField
    {
        public Field[,] fields;
        public BigField()
        {
            fields = new Field[3, 3];
        }
        public void SetFullEmpty()
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                    fields[i, j].SetEmpty();
            }
        }
        public string printLayer(int layerNum)
        {
            int internalLayer = layerNum % 3;
            /*if (internalLayer == 0 && layerNum != 0)
                internalLayer = 3;*/
            layerNum = (layerNum - internalLayer) / 3;
            StringBuilder sb = new StringBuilder(0);
            for(int i = 0; i < 3; i++)
            {
                sb.Append(fields[i, layerNum].printLayer(internalLayer));
                if (i != 2)
                    sb.Append(" ");
            }
            return sb.ToString();
        }
    }
}
/*class Program
{
    static void Main(string[] args)
    {
        string length = Console.ReadLine();
        string input = Console.ReadLine();
        int changing = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i <= input.Length - 2; i += 2)
        {
            if (input[i] == input[i + 1])
            {
                if (input[i] == 'a') { sb.Append(input[i] + "b"); }
                else { sb.Append(input[i] + "a"); }
                changing++;
            }
            else
                sb.Append(input[i] + "" + input[i + 1]);
        }
        Console.WriteLine(changing);
        Console.WriteLine(sb.ToString());
        Console.ReadKey();
    }
}*/


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

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      var f = new char[9][];
      ReadField(f);
      var x = input.ReadInt() - 1;
      var y = input.ReadInt() - 1;
      var fx = x % 3;
      var fy = y % 3;
      if (!TryFillField(f, fx, fy))
        FillAll(f);
      PrintField(f);
    }

    private void ReadField(char[][] f)
    {
      for (int i = 0; i < 9; i++)
      {
        if (i != 0 && i % 3 == 0)
          input.ReadLine();
        f[i] = string.Join("", input.ReadLine().Split()).ToCharArray();
      }
    }

    private void PrintField(char[][] f)
    {
      var sb = new StringBuilder();
      for (int i = 0; i < 9; i++)
      {
        if (i != 0 && i % 3 == 0)
          sb.AppendLine();
        for (int j = 0; j < 9; j++)
        {
          if (j != 0 && j % 3 == 0)
            sb.Append(' ');
          sb.Append(f[i][j]);
        }
        sb.AppendLine();
      }
      Console.Write(sb);
    }

    private void FillAll(char[][] f)
    {
      for (int i = 0; i < 9; i++)
        for (int j = 0; j < 9; j++)
          if (f[i][j] == '.')
            f[i][j] = '!';
    }

    private bool TryFillField(char[][] f, int fx, int fy)
    {
      bool result = false;
      for (int i = 0; i < 3; i++)
      {
        for (int j = 0; j < 3; j++)
        {
          int lx = fx * 3 + i;
          int ly = fy * 3 + j;
          if (f[lx][ly] == '.')
          {
            f[lx][ly] = '!';
            result = true;
          }
        }
      }
      return result;
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }

    #region Service functions

    private const string ABC = "abcdefghijklmnopqrstuvwxyz";

    private static void AddCount<T>(Dictionary<T, int> counter, T item)
    {
      int count;
      if (counter.TryGetValue(item, out count))
        counter[item] = count + 1;
      else
        counter.Add(item, 1);
    }

    private static int GetCount<T>(Dictionary<T, int> counter, T item)
    {
      int count;
      return counter.TryGetValue(item, out count) ? count : 0;
    }

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

    #endregion
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public string ReadToEnd()
    {
      return this.reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

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

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

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}


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

namespace codeforces
{
    class C
    {
        static CodeforcesUtils CF = new CodeforcesUtils(
@"
0 0 0 1
0 0 0 1
1 0 1 1
1 0 1 1
");

        static void Main(string[] args)
        {
            bool b = true;
            Dictionary<string, int> c = new Dictionary<string, int>();
            List<int> xs = new List<int>();
            List<int> ys = new List<int>();
            int hc=0;
            for (int i = 0;i<4;i++)
            {
                string[] ss  = CF.ReadLine().Split(' ');
                int x1 = int.Parse(ss[0]);
                int y1 = int.Parse(ss[1]);
                int x2 = int.Parse(ss[2]);
                int y2 = int.Parse(ss[3]);

                if (!_l(x1, y1, x2, y2))
                {
                    b = false;
                    break;
                }

                if (x1 != x2)
                    hc++;

                string p1 = x1 +","+ y1;
                if (!c.ContainsKey(p1))
                    c.Add(p1, 0);
                c[p1]++;

                string p2 = x2 + "," + y2;
                if (!c.ContainsKey(p2))
                    c.Add(p2, 0);
                c[p2]++;

                if( !xs.Contains(x1) )
                    xs.Add(x1);
                if (!xs.Contains(x2))
                    xs.Add(x2);
                if (!ys.Contains(y1))
                    ys.Add(y1);
                if (!ys.Contains(y2))
                    ys.Add(y2);
            }

            if (b)
            {
                if (hc != 2)
                    b = false;
                else if (xs.Count != 2 || ys.Count != 2)
                    b = false;
                else if (c.Count != 4)
                    b = false;
                else
                {
                    foreach (int v in c.Values)
                    {
                        if (v != 2)
                        {
                            b=false;
                            break;
                        }
                    }
                }
            }

            if (b)
                CF.WriteLine("YES");
            else
                CF.WriteLine("NO");

        }

        static bool _l(int x1,int y1,int x2,int y2)
        {
            if( x1!=x2&&y1!=y2)
                return false;
            if (x1 == x2 && y1 == y2)
                return false;
            return true;
        }

        #region test

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

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

                string s = null;
                if (_lines.Count > 0)
                {
                    s = _lines[0];
                    _lines.RemoveAt(0);
                }
                return s;
#else
            return Console.In.ReadLine();
#endif
            }

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

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

            public CodeforcesUtils(string test_input)
            {
                _test_input = test_input;
            }

            string _test_input;

            List<string> _lines;
        }

        #endregion
    }
}


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
{
    bool NextPerm(int[] a)
    {
        int n = a.Length;
        for (int k = n - 2; k >= 0; k--)
            if (a[k] < a[k + 1])
                for (int l = n - 1; l >= 0; l--)
                    if (a[k] < a[l])
                    {
                        Swap(ref a[k], ref a[l]);
                        for (int i = k + 1, j = n - 1; i < j; i++, j--)
                            Swap(ref a[i], ref a[j]);
                        return true;
                    }
        return false;
    }

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

    public void Solve()
    {
        var a = ReadIntMatrix(4);

        var p = Enumerable.Range(0, 4).ToArray();
        do
        {
            if (a[p[0]][1] != a[p[0]][3] || a[p[1]][0] != a[p[1]][2] || a[p[2]][1] != a[p[2]][3] || a[p[3]][0] != a[p[3]][2])
                continue;
            int x1 = Math.Min(a[p[0]][0], a[p[0]][2]);
            int x2 = Math.Max(a[p[0]][0], a[p[0]][2]);
            int y1 = Math.Min(a[p[1]][1], a[p[1]][3]);
            int y2 = Math.Max(a[p[1]][1], a[p[1]][3]);
            if (x1 == x2 || y1 == y2 || a[p[0]][1] != y1 || a[p[1]][0] != x2 || Math.Min(a[p[2]][0], a[p[2]][2]) != x1 || Math.Max(a[p[2]][0], a[p[2]][2]) != x2 ||
                a[p[2]][1] != y2 || Math.Min(a[p[3]][1], a[p[3]][3]) != y1 || Math.Max(a[p[3]][1], a[p[3]][3]) != y2 || a[p[3]][0] != x1)
                continue;
            Write("YES");
            return;
        } while (NextPerm(p));
        Write("NO");
    }

    #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());
        //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)
        {
            Console.WriteLine(ex);
#if DEBUG
#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;
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 = 998244353;

            int n = ReadInt();
            int k = ReadInt();
            long l = ReadInt();

            int N = 2 * n + 2;
            long[][,] a = new long[2][,];
            a[0] = new long[N, 2];
            a[0][0, 0] = 1;

            for (int i = 0; i < 2 * n + 1; i++)
            {
                int t = i % 2;
                a[1 - t] = new long[N, 2];
                for (int j = 0; j <= i; j++)
                {
                    for (int e = 0; e < 2; e++)
                    {
                        if (e == 0 && j >= k)
                        {
                            a[1 - t][j, 1] += a[t][j, e];
                            Fix(ref a[1 - t][j, 1], MOD);
                        }
                        if (j > 0)
                        {
                            a[1 - t][j - 1, e] = (a[1 - t][j - 1, e] + j * a[t][j, e]) % MOD;
                        }
                        if (i + j - e <= 2 * n - 2)
                        {
                            a[1 - t][j + 1, e] += a[t][j, e];
                            Fix(ref a[1 - t][j + 1, e], MOD);
                        }
                    }
                }
            }

            long ans = a[1][0, 1];
            ans = ans * BinPower(2, n, MOD) % MOD;
            ans = ans * l % MOD;

            long f = 1;
            for (int i = 1; i <= n; i++)
            {
                f = f * i % MOD;
            }
            ans = ans * f % MOD;
            for (int i = n + 1; i <= 2 * n + 1; i++)
            {
                f = f * i % MOD;
            }
            ans = ans * Inv(f, MOD) % MOD;

            Writer.WriteLine(ans);
        }

        public static void Fix(ref long x, long mod)
        {
            if (x >= mod)
            {
                x -= mod;
            }
        }

        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 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);
            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.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 = 998244353;

            int n = ReadInt();
            int k = ReadInt();
            long l = ReadInt();

            int N = 2 * n + 2;
            long[][,] a = new long[2][,];
            long[][,] b = new long[2][,];
            a[0] = new long[N, 2];
            b[0] = new long[N, 2];
            a[0][0, 0] = 1;
            b[0][0, 0] = 1;

            for (int i = 0; i < 2 * n + 1; i++)
            {
                int t = i % 2;
                a[1 - t] = new long[N, 2];
                b[1 - t] = new long[N, 2];
                for (int j = 0; j <= i; j++)
                {
                    for (int e = 0; e < 2; e++)
                    {
                        if (e == 0)
                        {
                            if (j >= k)
                            {
                                a[1 - t][j, 1] += a[t][j, e];
                                Fix(ref a[1 - t][j, 1], MOD);
                            }
                            b[1 - t][j, 1] += b[t][j, e];
                            Fix(ref b[1 - t][j, 1], MOD);
                        }
                        if (j > 0)
                        {
                            a[1 - t][j - 1, e] = (a[1 - t][j - 1, e] + j * a[t][j, e]) % MOD;
                            b[1 - t][j - 1, e] = (b[1 - t][j - 1, e] + j * b[t][j, e]) % MOD;
                        }
                        if (i + j - e <= 2 * n - 2)
                        {
                            a[1 - t][j + 1, e] += a[t][j, e];
                            Fix(ref a[1 - t][j + 1, e], MOD);
                            b[1 - t][j + 1, e] += b[t][j, e];
                            Fix(ref b[1 - t][j + 1, e], MOD);
                        }
                    }
                }
            }

            long ans = a[1][0, 1] * Inv(b[1][0, 1], MOD) % MOD;
            ans = ans * l % MOD;

            Writer.WriteLine(ans);
        }

        public static void Fix(ref long x, long mod)
        {
            if (x >= mod)
            {
                x -= mod;
            }
        }

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

namespace WarmingUpC_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] numbers = Console.ReadLine().Split(' ');
            double c = double.Parse(numbers[4]), a = double.Parse(numbers[0]), b = double.Parse(numbers[1]), w = double.Parse(numbers[2]), x = double.Parse(numbers[3]);
            double Result = Math.Ceiling((-b + (c - a) * x + 0.0) / (w - x)) + c - a;
            Console.WriteLine(Math.Max(0, Result));
        }
    }
}


#define Online
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.IO;

delegate double F (double x);

delegate decimal Fdec (decimal x);

partial class Program
{
	public static StreamReader sr;
	public static StreamWriter sw;

	static void Main (string[] args)
	{

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

		B ();

#if Online
		Console.ReadLine ();
#endif

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

	}

	static void A ()
	{
	}

	static void B ()
	{
		int a, b, w, x, c;
		a = NextInt ();
		b = NextInt ();
		w = NextInt ();
		x = NextInt ();
		c = NextInt ();
		long time = long.MaxValue;
		long[] t = new long[1001];
		long[] d = new long[1001];
		int[] last = new int[1001];
		long[] th = new long[1001];
		long[] th_t = new long[1001];
		int[] last_th = new int[1001];
		for (int i=0; i<t.Length; i++) {
			int _b = i;
			int j = 0;
			int cnt = 0;
			while (_b>=x) {
				_b -= x;
				++j;
			}
			while (_b<x) {
				++cnt;
				_b = w - (x - _b);
				j++;
			}
			last [i] = _b;
			t [i] = j;
			d [i] = cnt;
		}
		for (int i=0; i<t.Length; i++) {
			int _b = i;
			while (th_t[i]-th[i]<1000) {
				th [i] += d [_b];
				th_t [i] += t [_b];
				_b = last [_b];

			}
			last_th [i] = _b;
		}

		long left = 0;
		long right = time;
		long mid = 0;
		while (left<right) {
			mid = (left + right) / 2;
			time = mid;
			long _a = a;
			long _c = c;
			int _b = b;
			while (_c-th_t[_b]>_a-th[_b]) {
				_a -= th [_b];
				_c -= th_t [_b];
				time -= th_t [_b];
				_b = last_th [_b];
			}
			while (_c-t[_b]>_a-d[_b]) {
				time -= t [_b];
				_c -= t [_b];
				_a -= d [_b];
				_b = last [_b];
			}
			while (_b>=x && _c>_a) {
				--_c;
				--time;
				_b -= x;
			}
			while (_b<x && _c>_a) {
				--_a;
				--_c;
				_b = w - (x - _b);
				--time;
			}
			if (time >= 0) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		Console.WriteLine (right);
	}

	static void C ()
	{

	}

	static void D ()
	{

	}

	static void E ()
	{

	}

	static void TestGen ()
	{

	}

}

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

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

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

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

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

static class ArrayUtils
{
	static void Swap<T> (T[] a, int l, int r)
	{
		T t = a [l];
		a [l] = a [r];
		a [r] = t;
	}

	public static bool NextPermutation (int[] a)
	{
		bool isOkay = false;
		int n = a.Length;
		for (int i=n-2; i>=0; i--) {
			if (a [i] < a [i + 1]) {
				isOkay = true;
				int j = i + 1;
				while (j+1<n && a[j+1]>a[i]) {
					j++;
				}
				Swap (a, i, j);
				for (j=1; i+j<n-j; j++) {
					Swap (a, i + j, n - j);
				}
				break;
			}
		}
		return isOkay;
	}

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

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

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

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

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

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

	public static void Merge_Sort<T> (T[]A, int p, int r, Comparison<T> comp)
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		Merge_Sort (A, p, r, L, R, comp);
	}

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

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

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

	public static void Merge_Sort<T> (T[]A, int p, int r)where T:IComparable<T>
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		Merge_Sort (A, p, r, L, R);
	}

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

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

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

	public static void Merge_Sort_Non_Recursive<T> (T[] A, int p, int r) where T : IComparable<T>
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		int k = 1;
		while (k < r - p + 1) {
			int i = 0;
			while (i < r) {
				int _r = Math.Min (i + 2 * k - 1, r);
				int q = Math.Min (i + k - 1, r);
				Merge (A, i, q, _r, L, R);
				i += 2 * k;
			}
			k <<= 1;
		}
	}

	public static void Merge_Sort_Non_Recursive<T> (T[] A, int p, int r, Comparison<T> comp)
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		int k = 1;
		while (k < r - p + 1) {
			int i = 0;
			while (i < r) {
				int _r = Math.Min (i + 2 * k - 1, r);
				int q = Math.Min (i + k - 1, r);
				Merge (A, i, q, _r, L, R, comp);
				i += 2 * k;
			}
			k <<= 1;
		}
	}

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

partial class Program
{
	static string[] tokens = new string[0];
	static int cur_token = 0;

	static void ReadArray (char sep)
	{
		cur_token = 0;
		tokens = Console.ReadLine ().Split (sep);
	}

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

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

	static int NextInt ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return int.Parse (tokens [cur_token++]);
	}

	static long NextLong ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return long.Parse (tokens [cur_token++]);
	}

	static double NextDouble ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return double.Parse (tokens [cur_token++]);
	}

	static decimal NextDecimal ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return decimal.Parse (tokens [cur_token++]);
	}

	static string NextToken ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return tokens [cur_token++];
	}

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


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;

class Program {
    static void Main(string[] args) {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        var solver = new Solver(sw);
        // var t = new Thread(solver.solve, 1 << 26); // 64 MB
        // t.Start();
        // t.Join();
        solver.solve();
        sw.Flush();
    }
}

class Solver {
    StreamWriter sw;
    Scan sc;
    void Prt(string a) => sw.WriteLine(a);
    void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
    void Prt(params object[] a) => Prt(string.Join(" ", a));
    public Solver(StreamWriter sw) {
        this.sw = sw;
        this.sc = new Scan();
    }

    public void solve() {
        int n, t;
        sc.Multi(out n, out t);
        var s = new int[n];
        var g = new int[n];
        for (int i = 0; i < n; i++)
        {
            sc.Multi(out s[i], out g[i]);
            --g[i];
        }
        memo = new long[n + 1][][][];
        for (int i = 0; i < n + 1; i++)
        {
            memo[i] = new long[n + 1][][];
            for (int j = 0; j < n + 1; j++)
            {
                memo[i][j] = new long[n + 1][];
                for (int k = 0; k < n + 1; k++)
                {
                    memo[i][j][k] = new long[4];
                    for (int l = 0; l < 4; l++)
                    {
                        memo[i][j][k][l] = -1;
                    }
                }
            }
        }
        long ans = 0;
        for (int i = 0; i < (1 << n); i++)
        {
            int sum = 0;
            var cnt = new int[3];
            for (int j = 0; j < n; j++)
            {
                if (((i >> j) & 1) == 1) {
                    sum += s[j];
                    ++cnt[g[j]];
                }
            }
            if (sum != t) continue;
            ans += dfs(cnt[0], cnt[1], cnt[2], 3);
        }
        Prt(ans % M);
    }
    long[][][][] memo;
    long dfs(int a, int b, int c, int prev) {
        if (a < 0 || b < 0 || c < 0) return 0;
        if (a == 0 && b == 0 && c == 0) return 1;
        if (memo[a][b][c][prev] != -1) return memo[a][b][c][prev];
        long sum = 0;
        if (prev != 0) sum += dfs(a - 1, b, c, 0) * a;
        if (prev != 1) sum += dfs(a, b - 1, c, 1) * b;
        if (prev != 2) sum += dfs(a, b, c - 1, 2) * c;
        return memo[a][b][c][prev] = sum % M;
    }
}

class pair<T, U> : IComparable<pair<T, U>> {
    public T v1;
    public U v2;
    public pair() : this(default(T), default(U)) {}
    public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; }
    public int CompareTo(pair<T, U> a) {
        int c = Comparer<T>.Default.Compare(v1, a.v1);
        return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
    }
    public override string ToString() => v1 + " " + v2;
    public void Deconstruct(out T a, out U b) { a = v1; b = v2; }
}
static class util {
    public static readonly int M = 1000000007;
    // public static readonly int M = 998244353;
    public static readonly long LM = 1L << 60;
    public static readonly double eps = 1e-11;
    public static void DBG(string a) => Console.Error.WriteLine(a);
    public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
    public static void DBG(params object[] a) => DBG(string.Join(" ", a));
    public static void Assert(bool cond) { if (!cond) throw new Exception(); }
    public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2);
    public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> {
        for (int i = 0; i < a.Count && i < b.Count; i++)
            if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]);
        return a.Count.CompareTo(b.Count);
    }
    public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w;
    static readonly int[] dd = { 0, 1, 0, -1 };
    // static readonly string dstring = "RDLU";
    public static P[] adjacents(int i, int j)
        => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1])).ToArray();
    public static P[] adjacents(int i, int j, int h, int w)
        => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1]))
                                         .Where(p => inside(p.v1, p.v2, h, w)).ToArray();
    public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);
    public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w);
    public static Dictionary<T, int> compress<T>(this IEnumerable<T> a)
        => a.Distinct().OrderBy(v => v).Select((v, i) => new { v, i }).ToDictionary(p => p.v, p => p.i);
    public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union));
    public static T[] inv<T>(this Dictionary<T, int> dic) {
        var res = new T[dic.Count];
        foreach (var item in dic) res[item.Value] = item.Key;
        return res;
    }
    public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; }
    public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; }
    public static T[] copy<T>(this IList<T> a) {
        var ret = new T[a.Count];
        for (int i = 0; i < a.Count; i++) ret[i] = a[i];
        return ret;
    }
}

class Scan {
    StreamReader sr;
    public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
    public Scan(string path) { sr = new StreamReader(path); }
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public string Str => sr.ReadLine().Trim();
    public pair<T, U> Pair<T, U>() {
        T a; U b;
        Multi(out a, out b);
        return new pair<T, U>(a, b);
    }
    public P P => Pair<int, int>();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
    public string[] StrArr => Str.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>()    ? ct<T, int>(int.Parse(s))
                       : eq<T, long>()   ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>()   ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    public void Multi<T>(out T a) => a = cv<T>(Str);
    public void Multi<T, U>(out T a, out U b)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); }
    public void Multi<T, U, V>(out T a, out U b, out V c)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); }
    public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); }
    public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void solve()
    {
        int N = cin.nextint;
        int T = cin.nextint;

        var A = new int[N];
        var G = new int[N];
        var co = new BinomialCoefficient(20);

        for (int i = 0; i < N; i++)
        {
            A[i] = cin.nextint;
            G[i] = cin.nextint - 1;
        }

        ModInt ans = 0;
        for (int S = 0; S < 1 << N; S++)
        {
            int time = 0;
            var type = new int[3];
            for (int i = 0; i < N; i++)
            {
                if ((S >> i & 1) == 1)
                {
                    time += A[i];
                    type[G[i]]++;
                }
            }
            if (time != T)
            {
                continue;
            }
            int X = type[0];
            int Y = type[1];
            int Z = type[2];

            var dp = new long[type[0] + 1, type[1] + 1, type[2] + 1, 4];

            for (int i = 0; i <= X; i++)
            {
                for (int j = 0; j <= Y; j++)
                {
                    for (int k = 0; k <= Z; k++)
                    {
                        for (int l = 0; l < 4; l++)
                        {
                            dp[i, j, k, l] = -1;
                        }
                    }
                }
            }
            ModInt ret = calc(X, Y, Z, 3, dp);
            if (X > 1) ret = ret * co.fact[X];
            if (Y > 1) ret = ret * co.fact[Y];
            if (Z > 1) ret = ret * co.fact[Z];
            ans += ret;

        }
        WriteLine(ans);
    }

    long calc(int x, int y, int z, int before, long[,,,] dp)
    {
        //WriteLine(x + " " + y + " " + z);
        if (dp[x, y, z, before] >= 0)
        {
            return dp[x, y, z, before];
        }
        if (x == 0 && y == 0 && z == 0)
        {
            return 1;
        }

        long ret = 0;
        if (x > 0 && before != 0)
        {
            ret += calc(x - 1, y, z, 0, dp);
        }
        if (y > 0 && before != 1)
        {
            ret += calc(x, y - 1, z, 1, dp);
        }
        if (z > 0 && before != 2)
        {
            ret += calc(x, y, z - 1, 2, dp);
        }
        ret %= mod;
        return dp[x, y, z, before] = ret;
    }

}

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

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

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

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

class BinomialCoefficient
{
    public ModInt[] fact, ifact;
    /// <summary>
    /// <paramref name="n"/>は <paramref name="Mod"/>未満でお願いします。
    /// </summary>
    /// <param name="n"></param>
    public BinomialCoefficient(ModInt _n)
    {
        int n = (int)_n.num;
        fact = new ModInt[n + 1];
        ifact = new ModInt[n + 1];
        fact[0] = 1;
        for (int i = 1; i <= n; i++)
            fact[i] = fact[i - 1] * i;
        ifact[n] = ModInt.Inverse(fact[n]);
        for (int i = n - 1; i >= 0; i--)
            ifact[i] = ifact[i + 1] * (i + 1);
        ifact[0] = ifact[1];
    }
    public ModInt this[int n, int r]
    {
        get
        {
            if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
            return fact[n] * ifact[n - r] * ifact[r];
        }
    }
    public ModInt RepeatedCombination(int n, int k)
    {
        if (k == 0) return 1;
        return this[n + k - 1, k];
    }
}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}


using System;

namespace Обрамление_дверей
{
    class Program
    {
        static void Main(string[] args)
        {
            int barLength = int.Parse(Console.ReadLine());
            int borderLength = int.Parse(Console.ReadLine());
            int upperBorderLength = int.Parse(Console.ReadLine());

            int scrap, barNum = 0, aNum=0,bNum=0;

            while (true)
            {
                if (upperBorderLength <= borderLength && bNum < 2 || aNum >= 4 && bNum < 2)
                {
                    scrap = barLength;
                    barNum++;
                    scrap -= upperBorderLength;
                    bNum++;
                }
                else if(aNum<4 || bNum>=2 && aNum<4)
                {
                    scrap = barLength;
                    barNum++;
                    scrap -= borderLength;
                    aNum++;
                }
                else
                {
                    break;
                }
                while (true)
                {
                    int aTmp = scrap - borderLength;
                    int bTmp = scrap - upperBorderLength;
                    if (aTmp>=0&&aTmp<=bTmp&&aNum<4 || aTmp>=0&&aNum<4&&bNum>=2 || bTmp<0 && aNum<4 && aTmp>=0)
                    {
                        scrap = aTmp;
                        aNum++;
                    }
                    else if (bTmp>=0&&bNum<2 || bTmp >= 0 && bNum < 2 && aNum >= 4 || aTmp<0 && bTmp<2 && bTmp>=0)
                    {
                        scrap = bTmp;
                        bNum++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Console.WriteLine(barNum);
        }
    }
}


using System;
using System.Collections.Generic;

namespace CodeForceCs
{
    static class Program
    {
        static void Main(string[] args)
        {
            Solver solver = new _Q910B();
            solver.SolveProblem();
            //Console.ReadKey();
        }
    }

    abstract class Solver
    {
        abstract public void SolveProblem();
    }

    class _Q910B : Solver
    {
        int n, a, b;
        List<int> need = new List<int>();
        override public void SolveProblem()
        {
            n = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            Console.WriteLine(GetResult());
        }

        int GetResult()
        {

            if (n >= 4 * a + 2 * b)
                return 1;

            if (n >= 2 * a + b)
                return 2;

            if (a >= b)
            {
                if (n >= 2 * a)
                    return 3;

                if (n >= a + b)
                    return 4;

                if (n >= 2 * b)
                    return 5;
            }
            else
            {
                if (n >= a + b || n >= 4 * a)
                    return 3;

                if (n >= 2 * a)
                    return 4;
            }
            return 6;
        }
    }

}


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

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

        private static void Main(string[] args)
        {
            string[] ss = reader.ReadLine().Split(' ');

            string sl = ss[0];
            string sr = ss[1];

            long count = 0;
            long d = 1;
            for (int i = 0; i < sl.Length - 1; i++)
            {
                d *= 10;
            }
            for (int i = sl.Length + 1; i < sr.Length; i++)
            {
                count += 9*d;
                d *= 10;
            }

            if (sl.Length == sr.Length)
            {
                count += Bigger(sl, true) - Bigger(sr, false);
            }
            else
            {
                count += Bigger(sl, true);
                count += 9*d - Bigger(sr, false);
            }

            writer.WriteLine(count);
            writer.Flush();
        }

        private static long Bigger(string sl, bool border)
        {
            long l = long.Parse(sl);
            if (sl.Length == 1)
            {
                return 10 - l - (border ? 0 : 1);
            }

            long d = 1;
            for (int i = 0; i < sl.Length - 2; i++)
            {
                d *= 10;
            }
            long count = d*(10 - (sl[0] - '0') - 1);

            char[] cl = sl.ToCharArray();
            cl[cl.Length - 1] = cl[0];

            var sd = new string(cl, 1, cl.Length - 2);
            if (sd.Length == 0)
                sd = "0";
            long dd = long.Parse(sd);
            long ll = long.Parse(new string(cl));

            if (ll < l || (ll == l && !border))
                dd++;

            count += d - dd;

            return count;
        }
    }
}


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

namespace CodeforcesSolution
{
    class ProgramCF
    {
        static ConsoleInput inp;
        static void Main ( string[] args )
        {
            try
            {
                if ( File.Exists ( @"d:\zin.txt" ) )
                    Console.SetIn ( new StreamReader ( @"d:\zin.txt" ) );
            }
            catch
            {
            }
            inp = new ConsoleInput ( );
            inp.ReadAll ( );
            long L = inp.NextLong ( );
            long R = inp.NextLong ( );
            long[] cntNumDigit = new long[20];
            cntNumDigit[1] = 10; //0~9
            cntNumDigit[2] = cntNumDigit[1] + 9; //0~99
            cntNumDigit[3] = cntNumDigit[2] + 10 * 9;
            long k=10;
            for ( int i = 4; i < 20; i++ )
            {
                k *= 10;
                cntNumDigit[i] = cntNumDigit[i - 1] + ( k * 9 );
            }
            long fr = F ( R, cntNumDigit );
            long fl = F ( L - 1, cntNumDigit );
            long ans = fr - fl;

            // start here
            // ====
            WriteLine ( ans );

        }

        private static long F ( long n, long[] cntNumDigit )
        {
            if ( n < 100 )
            {
                int cnt=0;
                for ( int i = 0; i <= n; i++ )
                {
                    string s = i.ToString ( );
                    if ( s[0] == s[s.Length - 1] )
                        cnt++;
                }
                return cnt;
            }
            else
            {
                int len = n.ToString().Length;
                long res=cntNumDigit[len - 1];
                long left = n.ToString ( )[0] - '0';
                long right = n % 10;
                long mid = long.Parse ( n.ToString ( ).Substring ( 1, len - 2 ) );
                for ( int i = 1; i <= 9; i++ )
                {
                    if ( i < left )
                    {
                        long add = long.Parse ( "1" + new string ( '0', len - 2 ) );
                        res += add;
                    }
                    else if ( i == left )
                    {
                        res += mid + 1;
                        if ( right < left )
                            res -= 1;
                    }
                }
                return res;
            }
        }

        private static void WriteLine ( object value )
        {
            Console.WriteLine ( string.Format ( CultureInfo.InvariantCulture, "{0}", value ) );
        }

        class ConsoleInput
        {
            List<string> lines = new List<string> ( );
            int idx=0;

            public void ReadAll ( )
            {
                while ( true )
                {
                    string line = Console.ReadLine ( );
                    if ( line == null )
                        break;
                    lines.AddRange ( line.Split ( ' ' ) );
                }
            }

            public string NextString ( )
            {
                return lines[idx++];
            }

            public int NextInt ( )
            {
                return int.Parse ( lines[idx++] );
            }

            public long NextLong ( )
            {
                return long.Parse ( lines[idx++] );
            }

            public double NextDouble ( )
            {
                return double.Parse ( lines[idx++] );
            }

        }

    }
}


using System;

namespace BlockedPoints
{
    partial class BlockedPoints
    {
        static void Main(string[] args)
        {
            long n;

            n = NextLong();

            Console.WriteLine(FindMinBlockedPoints(n));
        }

        private static long FindMinBlockedPoints(long n)
        {
            long count = 0, x, y, nSquared;
            bool hasMove = false;

            if (n == 0)
                return 1;

            if (n == 1)
                return 4;

            x = 1;
            y = n - 1;
            nSquared = n * n;

            while (x < n && y > 0)
            {
                if (x * x + y * y <= nSquared)
                {
                    count++;
                    x++;
                    hasMove = false;
                }
                else
                {
                    if (!hasMove)
                    {
                        y--;
                        hasMove = true;
                    }
                    else
                    {
                        x--;
                    }
                }
            }

            count += (y - 1);

            return count * 4 + 4;
        }
    }

    partial class BlockedPoints
    {
        static string[] tokens = new string[0];
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

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

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

        static int NextInt()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return tokens[cur_token++];
        }

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


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

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

        private static void Main(string[] args)
        {
            long n = Next();

            long count;
            if (n == 1)
                count = 4;
            else if (n == 0)
                count = 1;
            else if (n == 2)
                count = 8;
            else
            {

                long y = (long)Math.Sqrt(n/2*n)+2;
                long nn = n*n;

                while (2*y*y > nn)
                {
                    y--;
                }
                if (y*y + (y+1)*(y+1) > nn)
                {
                    count = (y)*8;
                }
                else
                {
                    count = (2*y + 1)*4;
                }
            }

            writer.WriteLine(count);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


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

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

        private static void Main(string[] args)
        {
            var xy = new int[4,2];
            for (int i = 0; i < 4; i++)
            {
                xy[i, 0] = Next();
                xy[i, 1] = Next() - 1;
            }

            var nn = new int[8,8];

            for (int i = 0; i < 3; i++)
            {
                nn[xy[i, 0], xy[i, 1]] = 2;
            }

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

                    int x = xy[2, 0] + i;
                    int y = xy[2, 1] + j;

                    if (x < 0 || x > 7 || y < 0 || y > 7)
                        continue;

                    nn[x, y] = 1;
                }
            }

            var dx = new[] {1, -1, 0, 0};
            var dy = new[] {0, 0, 1, -1};

            for (int i = 0; i < 4; i++)
            {
                for (int j = 1; j < 8; j++)
                {
                    int x = xy[0, 0] + dx[i]*j;
                    int y = xy[0, 1] + dy[i]*j;

                    if (x < 0 || x > 7 || y < 0 || y > 7)
                        break;

                    if (nn[x, y] == 2)
                    {
                        nn[x, y] = 1;
                        break;
                    }

                    nn[x, y] = 1;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 1; j < 8; j++)
                {
                    int x = xy[1, 0] + dx[i]*j;
                    int y = xy[1, 1] + dy[i]*j;

                    if (x < 0 || x > 7 || y < 0 || y > 7)
                        break;

                    if (nn[x, y] == 2)
                    {
                        nn[x, y] = 1;
                        break;
                    }

                    nn[x, y] = 1;
                }
            }

            //for (int i = 0; i < 8; i++)
            //{
            //    for (int j = 0; j < 8; j++)
            //    {
            //        Console.Write(nn[i,j]);
            //    }
            //    Console.WriteLine();
            //}

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    int x = xy[3, 0] + i;
                    int y = xy[3, 1] + j;

                    if (x < 0 || x > 7 || y < 0 || y > 7)
                        continue;

                    if (nn[x, y] != 1)
                    {
                        writer.WriteLine("OTHER");
                        writer.Flush();
                        return;
                    }
                }
            }

            writer.WriteLine("CHECKMATE");
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c >= 'a' && c <= 'z')
                    return c - 'a';
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            long m = ReadLong();
            long a = ReadLong();
            long b = ReadLong();

            long[] f = Enumerable.Repeat(-1L, (int)a).ToArray();
            f[0] = 0;
            long[] l = new long[a];

            var queue = new Queue<long>();
            queue.Enqueue(0);
            while (queue.Count > 0)
            {
                long cur = queue.Dequeue();
                long d = cur + (b - cur + a - 1) / a * a;
                long t = d - b;
                while (t >= 0 && f[t % a] < 0)
                {
                    f[t % a] = Math.Max(d, f[cur % a]);
                    l[t % a] = t;
                    // Writer.WriteLine($"{t % a} - {f[t % a]} {l[t % a]}");
                    queue.Enqueue(t);
                    t -= b;
                }
            }

            // WriteArray(f);

            long ans = 0;
            for (int i = 0; i < a; i++)
            {
                if (f[i] >= 0 && f[i] <= m)
                {
                    long k = Calc(m, l[i], a) - Calc(f[i] - 1, l[i], a);
                    // Writer.WriteLine($"{i} : {k}");
                    ans += k;
                }
            }

            Writer.WriteLine(ans);
        }

        public static long Calc(long st, long k, long a)
        {
            long full = (st - k + 1) / a;
            long ans = a * full * (full + 1) / 2;
            ans += (st - k + 1) % a * (full + 1);
            return ans;
        }

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

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

namespace TestProject
{
    class Program
    {
        static void Main(string[] args)
        {
            //read input
            var hw = Console.ReadLine().Split(' ');
            var h = int.Parse(hw[0]);
            var w = int.Parse(hw[1]);

            var field = new List<B>();
            for (var i = 0; i < h; i++)
            {
                var row = Console.ReadLine().ToCharArray();
                for (var j = 0; j < w; j++)
                {
                    if (row[j] == '*')
                    {
                        field.Add(new B { X = j, Y = i });
                    }
                }
            }

            var mouse = new B { Y = 0, X = 0 };
            var count = 0;
            //move mouse
            while (field.Any())
            {
                field = field.Where(b => b.X >= mouse.X && b.Y >= mouse.Y).ToList();
                if(!field.Any())
                {
                    break;
                }
                field = field.OrderBy(b => b.X - mouse.X + b.Y - mouse.Y).ToList();
                if (!field.Any())
                {
                    break;
                }
                mouse = field.First();
                field.RemoveAt(0);
                count++;
            }
            Console.WriteLine(count);
            Console.ReadLine();
        }

        class B
        {
            public int X { get; set; }
            public int Y { get; set; }
        }
    }
}


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

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var height = st[0];
			var width = st[1];
			var field = new List<string>(height);
			for(var i =0; i < height; i++)
			{
				field.Add(Console.ReadLine());
			}
			var r = 0;
			var c = 0;
			var sum = field[r][c] == '*' ? 1:0;
			while(r!= height -1 || c != width - 1)
			{
				var rightWithStrawberry = c + 1 < width && field[r][c+1] == '*';
				var downWithStrawberry = r + 1 < height && field[r+1][c] == '*';
				if (rightWithStrawberry)
				{
					c++;
					sum++;
					continue;
				}
				if (downWithStrawberry)
				{
					r++;
					sum++;
					continue;
				}
				if (c + 1 < width) c++;
				else r++;
			}
			Console.WriteLine(sum);
		}
	}
}