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

namespace G.GangUp
{
    internal static class Program
    {
        public static void Main(string[] args)
        {
            var nmkcd = Console.ReadLine().Split();
            var n = int.Parse(nmkcd[0]);
            var m = int.Parse(nmkcd[1]);
            var k = int.Parse(nmkcd[2]);
            var c = int.Parse(nmkcd[3]);
            var d = int.Parse(nmkcd[4]);

            var solver = new Solver(n, m, k, c, d);
            solver.Init();

            ReadInput(solver, m);

            for (var i = 0; i < k; i++)
                solver.IncreaseFlow();

            Console.WriteLine(solver.TotalCost);
        }

        private static void ReadInput(Solver solver, int m)
        {
            var memberHomes = Console.ReadLine().Split().GroupBy(int.Parse);
            foreach (var memberHome in memberHomes)
                solver.AddMemberHome(memberHome.Key - 1, memberHome.Count());

            for (var i = 0; i < m; i++)
            {
                var xy = Console.ReadLine().Split();
                var x = int.Parse(xy[0]) - 1;
                var y = int.Parse(xy[1]) - 1;

                solver.AddEdge(x, y);
                solver.AddEdge(y, x);
            }
        }
    }

    internal sealed class Solver
    {
        private static readonly Edge FakeEdge = new Edge();

        private readonly int _n, _m, _k, _c, _d;
        private readonly int _maxTime;
        private readonly Node _start, _sink;
        private readonly Node[,] _nodes;
        private readonly List<Edge>[] _nodeEdges;

        private readonly int[] _bestCosts;
        private readonly Edge[] _bestMoves;
        private readonly bool[] _isInQueue;
        private readonly Queue<Node> _bestPathSearchQueue;

        public Solver(int n, int m, int k, int c, int d)
        {
            _n = n;
            _m = m;
            _k = k;
            _c = c;
            _d = d;

            _maxTime = k + m;
            _nodes = new Node[n, _maxTime];

            _start = new Node() {Id = _nodes.Length};
            _sink = new Node() {Id = _nodes.Length + 1};

            var allNodesCount = _nodes.Length + 2;

            _nodeEdges = new List<Edge>[allNodesCount];
            _bestCosts = new int[allNodesCount];
            _bestMoves = new Edge[allNodesCount];
            _isInQueue = new bool[allNodesCount];
            _bestPathSearchQueue = new Queue<Node>(allNodesCount);

            for (var i = 0; i < allNodesCount; i++)
                _nodeEdges[i] = new List<Edge>(_maxTime);
        }

        public int TotalCost { get; private set; }

        public void Init()
        {
            var nodeId = 0;
            for (var node = 0; node < _n; node++)
                for (var time = 0; time < _maxTime; time++)
                    _nodes[node, time] = new Node() { Id = nodeId++ };

            for (var time = 0; time < _maxTime; time++)
                AddEdgeWithoutPair(_nodes[0, time], _sink, time * _c, _k);

            for (var node = 0; node < _n; node++)
            {
                var from = _nodes[node, 0];
                for (var time = 1; time < _maxTime; time++)
                {
                    var to = _nodes[node, time];
                    AddEdgePair(from, to, 0, _k);
                    from = to;
                }
            }

            _isInQueue[_sink.Id] = true;
        }

        public void AddMemberHome(int home, int count)
        {
            AddEdgeWithoutPair(_start, _nodes[home, 0], 0, count);
        }

        public void AddEdge(int from, int to)
        {
            for (var time = 0; time < _maxTime - 1; time++)
            {
                var nodeFrom = _nodes[from, time];
                var nodeTo = _nodes[to, time + 1];

                for (int people = 0, cost = 1; people < _k; people++, cost += 2)
                    AddEdgePair(nodeFrom, nodeTo, cost * _d, 1);
            }
        }

        public void IncreaseFlow()
        {
            FindBestPath();
            CommitBestPath();
            TotalCost += _bestCosts[_sink.Id];
        }

        private void FindBestPath()
        {
            for (var i = 0; i < _bestCosts.Length; i++)
                _bestCosts[i] = int.MaxValue;

            _bestCosts[_start.Id] = 0;
            _bestPathSearchQueue.Enqueue(_start);

            while (_bestPathSearchQueue.Count > 0)
            {
                var node = _bestPathSearchQueue.Dequeue();
                var costToNode = _bestCosts[node.Id];

                foreach (var edge in _nodeEdges[node.Id])
                {
                    if (edge.ResidualCapacity == 0)
                        continue;

                    var possibleCost = costToNode + edge.Cost;
                    if (possibleCost >= _bestCosts[edge.To.Id])
                        continue;

                    _bestCosts[edge.To.Id] = possibleCost;
                    _bestMoves[edge.To.Id] = edge;
                    if (_isInQueue[edge.To.Id])
                        continue;

                    _isInQueue[edge.To.Id] = true;
                    _bestPathSearchQueue.Enqueue(edge.To);
                }

                _isInQueue[node.Id] = false;
            }
        }

        private void CommitBestPath()
        {
            var cur = _bestMoves[_sink.Id];
            while (cur != null)
            {
                cur.ResidualCapacity--;
                cur.Paired.ResidualCapacity++;
                cur = _bestMoves[cur.From.Id];
            }
        }

        private void AddEdgePair(Node from, Node to, int cost, int capacity)
        {
            var forwardEdge = new Edge()
            {
                From = from,
                To = to,
                Cost = cost,
                ResidualCapacity = capacity,
            };

            var reverseEdge = new Edge()
            {
                From = to,
                To = from,
                Cost = -cost,
                ResidualCapacity = 0,
            };

            forwardEdge.Paired = reverseEdge;
            reverseEdge.Paired = forwardEdge;

            _nodeEdges[from.Id].Add(forwardEdge);
            _nodeEdges[to.Id].Add(reverseEdge);
        }

        private void AddEdgeWithoutPair(Node from, Node to, int cost, int capacity)
        {
            _nodeEdges[from.Id].Add(new Edge()
            {
                From = from,
                To = to,
                Cost = cost,
                ResidualCapacity = capacity,
                Paired = FakeEdge,
            });
        }
    }

    internal struct Node
    {
        public int Id { get; set; }
        public override string ToString() => Id.ToString();
    }

    internal sealed class Edge
    {
        public Node From { get; set; }
        public Node To { get; set; }
        public int Cost { get; set; }
        public int ResidualCapacity { get; set; }
        public Edge Paired { get; set; }
    }
}


using System;
using System.Linq;

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

            int[] array = Console.ReadLine().Split().Select(n => int.Parse(n)).ToArray();
            int count = 0;
            if ( array[1] != array[0] || array[1] != 1)
            {
                if (array[1] > array[0] / 2)
                {
                    count = array[0] - array[1];
                }
                else
                {
                    count = array[1] - 1;
                }
            }
            Console.WriteLine(count + array[0] * 3);
        }
    }
}


using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;

namespace Program
{

    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            ModInteger ans = 0;
            var table = new ModTable(2000050);

            n += 1;
            ans = 2 * table[2 * n - 1];
            ans *= table.inv[n] * table.inv[n - 1];
            IO.Printer.Out.WriteLine(ans - 1);

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

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

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

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

#region ModNumber
public partial struct ModInteger
{
    public const long Mod = (long)1e9 + 7;
    public long num;
    public ModInteger(long n) : this() { num = n % Mod; if (num < 0) num += Mod; }
    public override string ToString() { return num.ToString(); }
    public static ModInteger operator +(ModInteger l, ModInteger r) { var n = l.num + r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; }
    public static ModInteger operator -(ModInteger l, ModInteger r) { var n = l.num + Mod - r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; }
    public static ModInteger operator *(ModInteger l, ModInteger r) { return new ModInteger(l.num * r.num); }
    public static implicit operator ModInteger(long n) { return new ModInteger(n); }
}
#endregion
#region ModPow
public partial struct ModInteger
{
    static public ModInteger Pow(ModInteger v, ModInteger k)
    {
        ModInteger ret = 1;
        var n = k.num;
        for (; n > 0; n >>= 1, v *= v)
        {
            if ((n & 1) == 1)
                ret = ret * v;
        }
        return ret;
    }
}
#endregion
#region Inverse
public partial struct ModInteger
{
    static public ModInteger Inverse(ModInteger v)
    {
        long p, q;
        ExGCD(v.num, Mod, out p, out q);
        return new ModInteger(p % Mod + Mod);
    }
    static public long ExGCD(long a, long b, out long x, out long y)
    {
        var u = new long[] { a, 1, 0 };
        var v = new long[] { b, 0, 1 };
        while (v[0] != 0)
        {
            var t = u[0] / v[0];
            for (int i = 0; i < 3; i++)
            {
                var tmp = u[i] - t * v[i];
                u[i] = v[i];
                v[i] = tmp;
            }
        }
        x = u[1];
        y = u[2];
        if (u[0] > 0)
            return u[0];
        for (int i = 0; i < 3; i++)
            u[i] = -u[i];
        return u[0];

    }
}
#endregion
#region Permutaion
public class ModTable
{
    public ModInteger[] perm, inv;
    public ModTable(int n)
    {
        perm = new ModInteger[n + 1];
        inv = new ModInteger[n + 1];
        perm[0] = 1;
        for (int i = 1; i <= n; i++)
            perm[i] = perm[i - 1] * i;
        inv[n] = ModInteger.Inverse(perm[n]);
        for (int i = n - 1; i >= 0; i--)
            inv[i] = inv[i + 1] * (i + 1);
        inv[0] = inv[1];
    }
    public ModInteger this[int k] { get { return perm[k]; } }
    public ModInteger Inverse(int k) { return inv[k]; }
    public ModInteger Permutation(int n, int k)
    {
        if (n < 0 || n >= perm.Length)
            return 0;
        if (k < 0 || k >= n)
            return 0;
        return perm[n] * inv[n - k];
    }
    public ModInteger Combination(int n, int r)
    {
        if (n < 0 || n >= perm.Length || r < 0 || r > n) return 0;
        return perm[n] * inv[n - r] * inv[r];
    }
    public ModInteger RepeatedCombination(int n, int k)
    {
        if (k == 0) return 1;
        return Combination(n + k - 1, k);
    }
}
#endregion
#region CombinationTable
public class ModCombinationTable
{
    ModInteger[][] nCr;
    public ModCombinationTable(int n)
    {
        nCr = new ModInteger[n + 1][];
        for (int i = 0; i <= n; i++)
            nCr[i] = new ModInteger[i + 2];
        nCr[0][0] = 1;
        for (int i = 0; i <= n; i++)
        {
            nCr[i][0] = 1;
            for (int j = 1; j <= i; j++)
                nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
        }
    }
    public ModInteger this[int n, int r]
    {
        get
        {
            if (n < 0 || n > nCr.Length)
                throw new IndexOutOfRangeException("n<=0 || n>N ");
            if (r < 0 || r > n)
                throw new IndexOutOfRangeException("r<=0 ||r>n");
            return nCr[n][r];
        }
    }
    public ModInteger RepeatedCombination(int n, int k)
    {
        if (k == 0) return 1;
        return this[n + k - 1, k];
    }
}
#endregion


using System;
using System.Linq;
using System.Text;
class Program
{
  public static void Main(string[] args)
  {
    int[] inputs = Console.ReadLine().Split().Select(w => Convert.ToInt32(w)).ToArray();
    string stages =  new string (Console.ReadLine().OrderBy(c => c).ToArray());
    char current = stages[0];
    StringBuilder sb = new StringBuilder();
    sb.Append(current);
    //Console.WriteLine(stages);
    for(int i = 1;i<stages.Length;++i)
      if(stages[i] - current >= 2) {sb.Append(stages[i]); current = stages[i];}
    if(sb.ToString().Length < inputs[1]) Console.WriteLine(-1); else
      Console.WriteLine(sb.ToString().Substring(0,inputs[1]).Select(w => Convert.ToInt32(w) - 'a' + 1).Aggregate((a,b) => a+b));

  }
}


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

    class Solution
    {
        //x, y幸運
        //n 持っている正の整数
        //数字10^9がxとyだけで構成されているか
        //
        long n;
        long res;
        List<string> a = new List<string>();

        public void solve(string[] ind)
        {

            n = long.Parse(ind[0]);
            res = 0;

            for (int i = 1; i <= 9; i++)
            {
                if (i <= n) res++;
                search(i.ToString(), 1);
            }

            Console.WriteLine(res);
        }

        void search(string str, int count)
        {
            if (long.Parse(str) > n) return;
            int cnt = count;
            string stri;
            for (int i = 0; i <= 9; i++)
            {
                stri = i.ToString();

                if (long.Parse(str + stri) > n) continue;

                if (str.IndexOf(stri) == -1)
                {
                    if (cnt == 2) continue;
                    //else cnt++;
                }

                res++;
                if (long.Parse(str + stri + "0") <= n)
                {
                    if (str.IndexOf(stri) == -1)  search(str + stri, cnt+1);
                    else search(str + stri, cnt);
                }
            }
        }
    }

    class Program
    {
        const int INPUT_TYPE = 1;
        static int in_line = 1;
        static void Main(string[] args)
        {
            Solution s = new Solution();
            ArrayList indata = new ArrayList();

#if !DEBUG

            switch (INPUT_TYPE)
            {
                case 2: //１行目に入力する行数を選択する
                    in_line = int.Parse(Console.ReadLine());
                    indata.Add(in_line.ToString());
                    goto case 1;
                case 1: //入力する行数固定
                    for (int i = 0; i < in_line; i++)
                        indata.Add(Console.ReadLine());

                    s.solve((string[])indata.ToArray(typeof(string)));
                    break;
            }
#else
            string[] debug_files = {
                                       "test1.txt",
                                       //"test2.txt",
                                       //"test3.txt"
                                   };

            foreach (var fname in debug_files)
            {
                try
                {
                    s.solve(File.ReadAllLines(fname));
                }
                catch (FileNotFoundException)
                {
                    //スルー
                }

            }
#endif
        }
    }


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

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

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

            long sum = 0;

            for (int start = n - 2; start >= 0; start--)
            {
                long count = 4;
                if (start != 0)
                    count *= 3;
                if (start > 1)
                    count *= Pow(4, start - 1);
                if (start + n != 2*n - 2)
                    count *= 3;
                if (start + n < 2*n - 3)
                    count *= Pow(4, (n - start - 3));

                sum += count;
            }

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

        private static long Pow(long a, int k)
        {
            long r = 1;
            while (k > 0)
            {
                if ((k & 1) == 1)
                {
                    r = (r*a);
                }
                a = (a*a);
                k >>= 1;
            }
            return r;
        }

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


using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using Pair = System.IComparable;
using Point = System.Tuple<int, int>;

public class Solution : Helper
{
    public Solution()
    {
        // http://codeforces.com/contest/899/problem/D
        var n = readInt32();
        long ans = 0;
        //
        if (n < 5)
        {
            ans = n * (n - 1) / 2;
        }
        else
        {
            var bs = bestSum(n);
            var str = bs.ToString();
            var f = str[0] - '0';
            if (f == 9)
            {
                ans = cp(bs, n);
            }
            else
            {
                range(0, f).each(h =>
                {
                    ans += cp(int.Parse(str.Replace(
                        f.ToString(),
                        h.ToString()
                        )), n);
                });
            }
        }
        //
        Console.WriteLine(ans);
    }
    //
    int cp(int sum, int n)
    {
        var a = sum / 2 + 1;
        var b = sum - 1;
        return count(a, Math.Min(b, n));
    }
    int count(int left, int right)
    {
        if (left > right) return 0;
        return (int)(right - left + 1);
    }
    int bestSum(int n)
    {
        var a = n + n - 1;
        var b = a.ToString();
        var c = b[0] - '0';
        var l = b.Length;
        var nines = b.Reverse().TakeWhile(x => x == '9').Count();
        if (nines >= l - 1)
            return a;
        return int.Parse((c - 1) + new string('9', l - 1));
    }
}

#region Core helper library
[DebuggerNonUserCode]
static partial class Extension
{
    internal static IEnumerable<T> each<T>(this IEnumerable<T> stream, Action<T> act) { foreach (var elem in stream) act(elem); return stream; }
    internal static IEnumerable<KeyValuePair<int, T>> kvp<T>(this IEnumerable<T> stream) { return stream.Select((elem, idx) => new KeyValuePair<int, T>(idx, elem)); }
    internal static IEnumerable<T> each<T>(this IEnumerable<T> stream, Action<T, int> act) { stream.kvp().each(kvp => act(kvp.Value, kvp.Key)); return stream; }
    internal static IEnumerable<int> indexIndices<T>(this IList<T> list) { return Helper.range(0, list.Count - 1); }
    internal static TValue? getOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key) where TValue : struct
    { TValue ans; if (dict.TryGetValue(key, out ans)) return ans; return null; }
    internal static T? FirstOrNullable<T>(this IEnumerable<T> stream) where T : struct { foreach (var val in stream) return val; return null; }
    internal static List<T> Collect<T>(this IEnumerable<T> stream, int capacity) { var ans = new List<T>(capacity); ans.AddRange(stream); return ans; }
    internal static LinkedList<T> Collect<T>(this IEnumerable<T> stream) { return new LinkedList<T>(stream); }
}
[DebuggerNonUserCode]
public partial class Helper
{
    internal const int DEFAULT_BUFFER_SIZE = 4194304;
    internal static void fail(string reason = "ASSERTION FAILED") { throw new ApplicationException(reason); }
    internal static void debug(string reason = "ASSERTION FAILED") { Debug.Fail(reason); }
    internal static IEnumerable<int> range(int left, int right) { for (var i = left; i <= right; i++) yield return i; }
    internal static int? explainSearchIndex(int rawIndex) { if (rawIndex < 0) return null; return rawIndex; }
    internal static Pair pair<T1, T2>(T1 value1, T2 value2) { return Tuple.Create(value1, value2); }
}
#endregion

// additional plugable library
public partial class Helper
{
    #region STDIO
#if !DEBUG
    static void Main() { new Solution(); }
#endif
    static void eof() { throw new System.IO.EndOfStreamException(); }
    internal static string readLine_TRIM()
    { while (true) { var ans = Console.ReadLine(); if (ans == null) eof(); ans = ans.Trim(); if (ans.Any()) return ans; } }
    static IEnumerable<char> stream() { while (true) { var iread = Console.Read(); if (iread < 0) break; yield return (char)iread; } }
    static bool isWhitespace(char c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t'; }
    internal static string readString_TRIM(int maxCapacity)
    {
        var sb = new System.Text.StringBuilder(maxCapacity, maxCapacity);
        var iter = stream().SkipWhile(isWhitespace).TakeWhile(c => !isWhitespace(c));
        foreach (var c in iter) sb.Append(c);
        if (sb.Length == 0) eof(); return sb.ToString();
    }
    internal static long readLong64() { return long.Parse(readString_TRIM(21)); }
    internal static int readInt32() { return Convert.ToInt32(readLong64()); }
    #endregion
}
static partial class Extension
{

}


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

namespace acm
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] q = new string[8];
            int ans = 16;
            for (int i = 0; i < 8; ++i) q[i] = Console.ReadLine();
            for( int i = 0; i < ( 1 << 8 ); ++ i )
                for (int j = 0; j < (1 << 8); ++j)
                {
                    bool ok = true;
                    for (int ii = 0; ii < 8; ++ii)
                        for (int jj = 0; jj < 8; ++jj)
                        {
                            if (q[ii][jj] == 'B' && 0 == (i & (1 << ii)) && 0 == (j & (1 << jj))) ok = false;
                            if (q[ii][jj] == 'W' && ( 0 != (i & (1 << ii)) || 0 != (j & (1 << jj)))) ok = false;
                        }
                    if (ok)
                    {
                        int cur = 0;
                        for (int ii = 0; ii < 8; ++ii) if (0 != (i & (1 << ii))) ++cur;
                        for (int ii = 0; ii < 8; ++ii) if (0 != (j & (1 << ii))) ++cur;
                        ans = Math.Min(ans, cur);
                    }
                }
            Console.WriteLine(ans);
        }
    }
}


using System;
class test
{
    static long f(long b)
    {
        if (b < 10) return b;

        string tmp = b + "";
        long sum = 0;
        for (int i = 0; i < tmp.Length; i++)
        {
            sum += long.Parse(tmp[i] + "");
        }

        return sum;
    }

    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        long i = (long)(Math.Sqrt(n)) - f(n);

        if (i <= 0) i = 1;

        while (i * i + i<= n)
        {
            if (n % i != 0)
                {
                    i = i + 1;
                    continue;
                }

            if (i * i + (f(i) * i) == n)
            {
                Console.WriteLine(i);
                Console.ReadLine();
                return;
            }
            i = i + 1;
        }
        Console.WriteLine("-1");
        Console.ReadLine();
    }
}


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

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

        private static void Main(string[] args)
        {
            int x = Next();
            int y = Next();

            int d = x*x + y*y;
            if (x*y != 0)
            {
                for (int i = 2000 - 1; i >= 0; i--)
                {
                    if (i*i < d)
                    {
                        d = i+1;
                        break;
                    }
                }
                if (d*d == x*x + y*y)
                    writer.WriteLine("black");
                else writer.WriteLine(x*y > 0 ^ d%2 == 1 ? "white" : "black");
            }
            else if (x*y == 0)
            {
                writer.WriteLine("black");
            }

            writer.Flush();
        }

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


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

namespace ConsoleApp
{
    class Program
    {
        const double DefaultEpsilon = 1e-18;

        struct Vector
        {
            public double X;
            public double Y;

            public Vector(double x, double y)
            {
                X = x;
                Y = y;
            }
            public Vector(double angle)
            {
                X = Math.Cos(angle);
                Y = Math.Sin(angle);
            }

            public double Hypot()
            {
                return Math.Sqrt((X * X) + (Y * Y));
            }
            public double HypotSquared()
            {
                return (X * X) + (Y * Y);
            }
            public Vector RotateClockwise(double angle)
            {
                double cos = Math.Cos(angle);
                double sin = Math.Sin(angle);

                return new Vector(X * cos + Y * sin, X * -sin + Y * cos);
            }
            public Vector Perpendicular()
            {
                return new Vector(-Y, X);
            }
            public bool IsEqual(Vector vector, double epsilon = DefaultEpsilon)
            {
                return Equal(this.X, vector.X, epsilon) && Equal(this.Y, vector.Y, epsilon);
            }

            public static Vector operator +(Vector a)
            {
                return a;
            }
            public static Vector operator -(Vector a)
            {
                return new Vector(-a.X, -a.Y);
            }
            public static Vector operator +(Vector a, Vector b)
            {
                return new Vector(a.X + b.X, a.Y + b.Y);
            }
            public static Vector operator -(Vector a, Vector b)
            {
                return new Vector(a.X - b.X, a.Y - b.Y);
            }
            public static double Determinant(Vector a, Vector b)
            {
                return (a.X * b.Y) - (a.Y * b.X);
            }
            public static double DotProduct(Vector a, Vector b)
            {
                return (a.X * b.X) + (a.Y * b.Y);
            }
        }
        struct Line
        {
            public double A;
            public double B;
            public double C;

            public double slopeY => -A / B; // y = f'(x)
            public double slopeX => -B / A; // x = f'(y)

            public Line(Vector p1, Vector p2)
            {
                A = p2.Y - p1.Y;
                B = p1.X - p2.X;
                C = p2.X * p1.Y - p1.X * p2.Y;
            }
        }
        struct Segment
        {
            public Vector Left;
            public Vector Right;

            public Segment(Vector left, Vector right)
            {
                Left = left;
                Right = right;
            }

            public Line GetLine()
            {
                return new Line(Left, Right);
            }
            public bool IsOnTheSegment(Vector point, double epsilon = DefaultEpsilon)
            {
                Vector v1 = point - Left;
                Vector v2 = point - Right;
                double det = Vector.Determinant(v1, v2);
                double dotProd = Vector.DotProduct(v1, v2);

                return Equal(det, 0, epsilon) && LessOrEqual(dotProd, 0, epsilon);
            }
        }

        static Program()
        {
            // Comment this before submitting (in case of strandard input)
            //Console.SetIn(new StreamReader("input.txt"));
            //Console.SetOut(new StreamWriter("output.txt"));
        }
        static void Main()
        {
            //int testCases = int.Parse(Console.ReadLine());
            //for (int z = 0; z < testCases; z++)
            //{

            //}

            int[] data = ReadIntData();
            int n = data[0];
            int m = data[1];
            int k = data[2];
            int r = data[3];
            int c = data[4];

            data = ReadIntData();
            int ax = data[0];
            int ay = data[1];
            int bx = data[2];
            int by = data[3];

            if (ax > bx)
            {
                Swap(ref ax, ref bx);
            }
            if (ay > by)
            {
                Swap(ref ay, ref by);
            }

            //int dx = bx - ax;
            //int dy = by - ay;

            long total = (long)n * m;
            if ((ax != bx) || (ay != by))
            {
                total -= (long)r * c;
            }

            //total += (long)(ax - bx + r) * (ay - by + c);

            Console.WriteLine(PowQuick(k, total, 1_000_000_007));

            Console.Out.Close();
        }

        static bool Equal(double a, double b, double epsilon = DefaultEpsilon)
        {
            return Math.Abs(a - b) < epsilon;
        }
        static bool Greater(double a, double b, double epsilon = DefaultEpsilon)
        {
            return (a > b) && !Equal(a, b, epsilon);
        }
        static bool Less(double a, double b, double epsilon = DefaultEpsilon)
        {
            return (a < b) && !Equal(a, b, epsilon);
        }
        static bool GreaterOrEqual(double a, double b, double epsilon = DefaultEpsilon)
        {
            return (a > b) || Equal(a, b, epsilon);
        }
        static bool LessOrEqual(double a, double b, double epsilon = DefaultEpsilon)
        {
            return (a < b) || Equal(a, b, epsilon);
        }
        static double DegToRad(double angle)
        {
            return (angle / 180) * Math.PI;
        }
        static long LCM(long a, long b)
        {
            return (a / GCD(a, b)) * b;
        }
        static long GCD(long a, long b)
        {
            while (a != 0)
            {
                b %= a;
                Swap(ref a, ref b);
            }

            return b;
        }
        static long PowQuick(long b, long p)
        {
            long exp = b;
            long res = 1;

            while (p > 0)
            {
                if ((p % 2) == 1)
                {
                    res *= exp;
                }

                exp *= exp;
                p /= 2;
            }

            return res;
        }
        static long PowQuick(long b, long p, long mod)
        {
            long exp = b;
            long res = 1;

            while (p > 0)
            {
                if ((p % 2) == 1)
                {
                    res *= exp;
                    res %= mod;
                }

                exp *= exp;
                exp %= mod;
                p /= 2;
            }

            return res;
        }
        static uint BitCount(uint a)
        {
            a = ((a >> 1) & 0x55555555u) + (a & 0x55555555u);
            a = ((a >> 2) & 0x33333333u) + (a & 0x33333333u);
            a = ((a >> 4) & 0x0F0F0F0Fu) + (a & 0x0F0F0F0Fu);
            a = ((a >> 8) & 0x00FF00FFu) + (a & 0x00FF00FFu);
            a = ((a >> 16) & 0x0000FFFFu) + (a & 0x0000FFFFu);
            return a;
        }
        static bool AreAlmostEqual(double a, double b, double epsilon)
        {
            return Math.Abs(a - b) < epsilon;
        }
        static int Binary(int[] array, int val)
        {
            return Binary(array, val, 0, array.Length);
        }
        static int Binary(int[] array, int val, int left, int right)
        {
            if (val < array[0])
            {
                return 0;
            }

            while (right - left > 1)
            {
                int mid = (right + left) / 2;

                if (array[mid] <= val)
                {
                    left = mid;
                }
                else
                {
                    right = mid;
                }
            }

            return right;
        }
        static void Swap(ref int a, ref int b)
        {
            int temp = a;
            a = b;
            b = temp;
        }
        static void Swap(ref long a, ref long b)
        {
            long temp = a;
            a = b;
            b = temp;
        }
        static double[] ReadDoubleData(TextReader input)
        {
            return input.ReadLine()
                .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(val => double.Parse(val))
                .ToArray();
        }
        static double[] ReadDoubleData()
        {
            return ReadDoubleData(Console.In);
        }
        static int[] ReadIntData(TextReader input)
        {
            return input.ReadLine()
                .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(val => int.Parse(val))
                .ToArray();
        }
        static int[] ReadIntData()
        {
            return ReadIntData(Console.In);
        }
        static long[] ReadLongData(TextReader input)
        {
            return input.ReadLine()
                .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(val => long.Parse(val))
                .ToArray();
        }
        static long[] ReadLongData()
        {
            return ReadLongData(Console.In);
        }
    }
}


using System;
class Test {
    static int Main() {
        string [] str = Console.ReadLine().Split();
        int [] a = new int [str.Length];
        for(int k=0 ; k<str.Length ; k++){
            a[k] = int.Parse(str[k]);
        }
        if(a[0]==0){
            Console.WriteLine("YES");
            return 0;
        }
        int ta,tb;
        for(ta=0 ; ta<a[1] ; ta++){
            int tmp = a[2]-(ta*a[4]);
            if(tmp==a[0]){
                Console.WriteLine("YES");
                return 0;
            }
        }
        for(tb=0 ; tb<a[1] ; tb++){
            int tmp = a[3]-(tb*a[5]);
            if(tmp==a[0]){
                Console.WriteLine("YES");
                return 0;
            }
        }
        for(ta=0 ; ta<a[1] ; ta++){
            for(tb=0 ; tb<a[1] ; tb++){
                int tmp = (a[2]-(ta*a[4]))+(a[3]-(tb*a[5]));
                if(tmp==a[0]){
                    Console.WriteLine("YES");
                    return 0;
                }
            }
        }
        Console.WriteLine("NO");
        return 0;
    }
}


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
{
    public void Solve()
    {
        int x = ReadInt();
        int d = 0;
        while (x > 2000)
        {
            x -= 400;
            d++;
        }

        var d1 = new DateTime(x, 1, 1);
        for (int i = x + 1; ; i++)
        {
            var d2 = new DateTime(i, 1, 1);
            if (d1.DayOfWeek == d2.DayOfWeek && d1.AddDays(400).Day == d2.AddDays(400).Day)
            {
                Write(i + 400 * d);
                return;
            }
        }
    }

    #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.Linq;

namespace CSharp
{
    class _1143B
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            int max = 0;
            for (int prefix = 1; prefix < 1000; prefix++)
            {
                for (string suffix = string.Empty; suffix.Length <= 7; suffix += 9)
                {
                    if (long.Parse(prefix + suffix) <= n)
                    {
                        max = Math.Max(max, (prefix + suffix).Aggregate(1, (p, c) => p * (c - '0')));
                    }
                }
            }

            Console.WriteLine(max);
        }
    }
}


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

namespace File
{
    class Program
    {

        static long nod(long a, long b)
        {
            if (a < b) { long c = a; a = b; b = c; }
            long r;
            do
            {
                r = a % b;
                a = b;
                b = r;
            } while (r != 0);
            return a;
        }

        static void Main()
        {
            long[] cin = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long a = cin[0], b = cin[1], x = cin[2], y = cin[3];
            long d = nod(x, y);
            x /= d;
            y /= d;
            a /= x;
            b /= y;
            Console.WriteLine(Math.Min(a,b));
        }
    }
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            long x, k, a, b;
            {
                string[] input = Console.In.ReadToEnd().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                x = long.Parse(input[0]);
                k = long.Parse(input[1]);
                a = long.Parse(input[2]);
                b = long.Parse(input[3]);
            }
            long result = 0L;
            for (long smllr; x > 1L;)
            {
                if ((smllr = x % k) == 0L)
                {
                    if (((x - (smllr = x / k)) * a) <= b) { result += a * (x - 1L); x = 1L; break; }
                    else { x = smllr; result += b; }
                }
                else { result += smllr * a; x -= smllr; }
            }
            Console.WriteLine(x == 0L ? result - a : result);
        }
    }


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

namespace ProgrammingContest.Codeforces.Round53
{
    class A
    {
        public static void Main()
        {
            int[] xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss=>int.Parse(sss));
            int[] dx = new int[] { 0, 1, 0, -1 },
                  dy = new int[] { 1, 0, -1, 0 };
            int n = xs[0];
            int[,] dist = new int[n + 1, n + 1];
            bool[,] visited = new bool[n + 1, n + 1];
            for (int y = 1; y < n; y++)
                for (int x = 1; x < n; x++)
                    visited[x, y] = true;

            Queue<int> qx = new Queue<int>(), qy = new Queue<int>();
            qx.Enqueue(xs[1]); qy.Enqueue(xs[2]);
            while (true)
            {
                int xx = qx.Dequeue(),
                    yy = qy.Dequeue();
                if (xx == xs[3] && yy == xs[4]) break;
                for (int i = 0; i < 4; i++)
                {
                    int x = xx + dx[i],
                       y = yy + dy[i];
                    if (0 <= x && x <= n && 0 <= y && y <= n && !visited[x, y])
                    {
                        visited[x, y] = true;
                        qx.Enqueue(x);
                        qy.Enqueue(y);
                        dist[x, y] = dist[xx, yy] + 1;
                    }
                }
            }

            Console.WriteLine(dist[xs[3], xs[4]]);
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApp4
{
    class Program
    {

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

        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var span = str.Split(' ');
            long a = long.Parse(span[0]);
            long b = int.Parse(span[1]);

            if (b > a)
            {
                long t = b;
                b = a;
                a = t;
            }
            var div = a - b;
            if (div == 0 || a % b == 0)
            {
                Console.WriteLine(0);
                return;
            }
            int lim = (int)Math.Floor(Math.Sqrt(div));
            long lcm = long.MaxValue;
            long kmin = 0;
            for (int i = 1; i < lim; i++)
                if (a % i == b % i)
                {
                    long q = i;
                    long k = 0;
                    if (b % q != 0)
                    {
                        k = (div - b) % q;
                        if (k < 0) k += q;

                    }
                    long l = (a + k) * (b + k) / gcd(a + k, b + k);
                    if (l < lcm)
                    {
                        lcm = l;
                        kmin = k;
                    }
                    else if (l == lcm)
                        kmin = Math.Min(k, kmin);
                    k = 0;
                    q = div / i;
                    if (b % q != 0)
                    {
                        k = (q - b) % q;
                        if (k < 0) k += q;

                    }
                    l = (a + k) * (b + k) / gcd(a + k, b + k);
                    if (l < lcm)
                    {
                        lcm = l;
                        kmin = k;
                    }
                    else if (l == lcm)
                        kmin = Math.Min(k, kmin);

                }
            Console.WriteLine(kmin);
        }
    }
}


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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            double x = 0;
            double y = 0;
            string[] infox = Console.ReadLine().Split(' ');
            int countx = int.Parse(infox[0]);
            int basex = int.Parse(infox[1]);
            string[] Xd = Console.ReadLine().Split(' ');

            string[] infoy = Console.ReadLine().Split(' ');
            int county = int.Parse(infoy[0]);
            int basey = int.Parse(infoy[1]);
            string[] Yd = Console.ReadLine().Split(' ');

            double j = 0;
            for(int i = countx-1; i>=0; i--)
            {
                x += double.Parse(Xd[i]) * Math.Pow(basex, j);
                j++;
            }

            j = 0;
            for(int i=county-1; i>=0; i--)
            {
                y += double.Parse(Yd[i]) * Math.Pow(basey, j);
                j++;
            }

            if (x < y)
            {
                Console.WriteLine('<');
                return;
            }

            if(x>y)
            {
                Console.WriteLine('>');
                return;
            }

            Console.WriteLine('=');
        }
    }
}


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

namespace Task
{
    class Program
    {
        public class PossibleDigit
        {
            public long digit;
            public int possibleLength;

            public PossibleDigit(int p)
            {
                possibleLength = p;
            }
        }
        static void Main(string[] args)
        {
            /*string[] input = Console.ReadLine().Split(' ');

            int n = Convert.ToInt32(input[0]),
                m = Convert.ToInt32(input[1]),
                x = Convert.ToInt32(input[3]),
                y = Convert.ToInt32(input[4]);
            long k = Convert.ToInt64(input[2]);

            long max, min, serg;

            if (n == 1)
            {
                if (k % m == 0)
                {
                    serg = min = max = k / m;
                }
                else
                {
                    min = k / m;
                    max = min + 1;
                    serg = k % m < y ? min : max;
                }
            }
            else if (n == 2)
            {
                min = k / (n * m);
                max = (k % (n * m) == 0 || (k - n * m) % ((n - 1) * m) == 0) ? min : min + 1;
            }
            else
            {
                int[] count = new int[3];

                if (k < 100000)
                {
                    for (int i = 0; i < k; ++i)
                    {
                        if ((i / m) == 1 || )
                    }
                }
            }

            Console.WriteLine($"{max} {min} {serg}");*/

            int n = Convert.ToInt32(Console.ReadLine());
            string num = Console.ReadLine();

            long answer = 0;
            int cur = n.ToString().Length;
            List<PossibleDigit> nums = new List<PossibleDigit>() {new PossibleDigit(cur)};

            for (int i = num.Length; i >= 0;)
            {
                /*Console.WriteLine("Список");

                Console.WriteLine();
                Console.WriteLine(i);*/
                if (i - nums[nums.Count - 1].possibleLength >= 0)
                {
                    i -= nums[nums.Count - 1].possibleLength;
                    //Console.WriteLine(i + " " + nums[nums.Count - 1].possibleLength);
                }
                else
                {
                    nums[nums.Count - 1].possibleLength = i;
                    i = 0;
                }
                if (num.Length < cur)
                {
                    nums[nums.Count - 1].digit = Convert.ToInt32(num);
                    nums.Add(new PossibleDigit(cur));
                    break;
                }
                if (nums[nums.Count - 1].possibleLength == 0) break;
                //Console.WriteLine($"Convert.ToInt32(num.Substring({i}, {nums[nums.Count - 1].possibleLength})) {Convert.ToInt32(num.Substring(i, nums[nums.Count - 1].possibleLength))}");
                long temp = Convert.ToInt64(num.Substring(i, nums[nums.Count - 1].possibleLength));
                if (num.Substring(i, nums[nums.Count - 1].possibleLength)[0] == '0' && nums[nums.Count - 1].possibleLength != 1)
                    temp = int.MaxValue;
                //Console.WriteLine($"Ето темп{temp}");

                if (temp < n)
                {
                    nums[nums.Count - 1].digit = temp;
                    nums.Add(new PossibleDigit(cur));
                }
                else
                {
                    //Console.WriteLine(-1);
                    i += nums[nums.Count - 1].possibleLength--;
                    if (nums[nums.Count - 1].possibleLength == 0)
                        --nums[nums.Count - 2].possibleLength;
                }
            }

            /*foreach (var t in nums) Console.Write(t.digit + " ");
            Console.WriteLine();*/
            for(int i = nums.Count - 2; i >= 0; --i)
            {
                answer *= n;
                answer += nums[i].digit;
            }

            Console.Write(answer);
        }
    }
}


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

class P
{
    static void Main()
    {
        Console.WriteLine(Layer(int.Parse(Console.ReadLine())));
    }
    static int Layer(int i)
    {
        if (i == 1) return 1;
        if (i == 2) return 2;
        return i + Layer(i - 2);
    }
}


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

namespace trenvk
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            long res = 0;

            for (int i = 1; i <= nm[0]; i++)
            {
                res += (nm[1] + i) / 5 - (i + 1) / 5;
                if ((i + 1) % 5 == 0) res++;

            }
            Console.Write(res);
        }
    }
}


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

namespace cf762
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_cf762B();
            Console.Out.Flush();
        }

        public static void solve_cf762B()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            while (t-- > 0)
            {
                int n = Convert.ToInt32(Console.ReadLine());
                Dictionary<int, int> used = new Dictionary<int, int>();
                for (int i = 1; i * i <= n; i++)
                {
                    used.TryAdd(i * i, i * i);
                }
                for (int i = 1; i * i * i <= n; i++)
                {
                    used.TryAdd(i * i * i, i * i * i);
                }
                Console.WriteLine(used.Count);
            }
        }

        public static void solve_cf762A()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            while (t-- > 0)
            {
                string s = Console.ReadLine();
                int n = s.Length;
                if (n % 2 != 0)
                {
                    Console.WriteLine("NO");
                }
                else
                {
                    bool ok = true;
                    for (int i = 0; i < n / 2; i++)
                    {
                        if (s[i] != s[n / 2 + i])
                        {
                            ok = false;
                            break;
                        }
                    }
                    Console.WriteLine(ok ? "YES" : "NO");
                }
			}
        }
    }
}


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

namespace Codeforces
{
    class D
    {
        private static ThreadStart s_threadStart = new D().Go;
        private static bool s_time = false;
        private static double s_eps = 1e-16;

        static long mod = 1000000007;
        public static long Pow(long a, long n)
        {
            long res = 1L;
            while (n > 0)
            {
                if ((n & 1) != 0)
                    res = (res * a) % mod;
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

        private void Go()
        {
            long p = GetInt();
            long k = GetInt();

            if (k == 0)
            {
                Wl(Pow(p, p - 1));
            }
            else if (k == 1)
            {
                Wl(Pow(p, p));
            }
            else
            {
                long x = k;
                long kp = 1;
                while (x != 1)
                {
                    x *= k;
                    x %= p;
                    kp++;
                }

                Wl(Pow(p, (p - 1) / kp));
            }
        }

        #region Template

        public static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            Thread main = new Thread(new ThreadStart(s_threadStart), 200 * 1024 * 1024);
            timer.Start();
            main.Start();
            main.Join();
            timer.Stop();
            if (s_time)
                Wl(timer.ElapsedMilliseconds);
        }

        private static IEnumerator<string> ioEnum;
        private static string GetString()
        {
            while (ioEnum == null || !ioEnum.MoveNext())
            {
                ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();
            }

            return ioEnum.Current;
        }

        private static int GetInt()
        {
            return int.Parse(GetString(), CultureInfo.InvariantCulture);
        }

        private static long GetLong()
        {
            return long.Parse(GetString(), CultureInfo.InvariantCulture);
        }

        private static double GetDouble()
        {
            return double.Parse(GetString(), CultureInfo.InvariantCulture);
        }

        private static List<int> GetIntArr(int n)
        {
            List<int> ret = new List<int>(n);
            for (int i = 0; i < n; i++)
            {
                ret.Add(GetInt());
            }
            return ret;
        }

        private static void Wl<T>(T o)
        {
            if (o is double)
            {
                Wld((o as double?).Value, "");
            }
            else if (o is float)
            {
                Wld((o as float?).Value, "");
            }
            else
                Console.WriteLine(o.ToString());
        }

        private static void Wl<T>(IEnumerable<T> enumerable)
        {
            Wl(string.Join(" ", enumerable.Select(e => e.ToString()).ToArray()));
        }

        private static void Wld(double d, string format)
        {
            Wl(d.ToString(format, CultureInfo.InvariantCulture));
        }

        #endregion
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
class Solver
{
    void Solve()
    {
        var str = sc.ScanLine();
        var _d = new int[6];
        const string s = "ROYGBV";
        for (int i = 0; i < 6; i++)
            for (int j = 0; j < 6; j++)
                if (str[i] == s[j])
                    _d[i] = j;
        Array.Sort(_d);
        var set = new HashSet<long>();
        var ret = 0;
        do
        {
            var dice = new Dice(_d);
            if (set.Contains(dice.AsLong()))
                continue;
            ret++;
            for (int i = 0; i < 4; i++)
            {
                dice.RotationX();
                for (int j = 0; j < 4; j++)
                {
                    dice.RotationY();
                    for (int k = 0; k < 4; k++)
                    {
                        dice.RotationZ();
                        var code = dice.AsLong();
                        set.Add(code);

                    }
                }
            }
        } while (_d.NextPermutation(0,6));
        Printer.PrintLine(ret);

    }

    static void Main()
    {
#if DEBUG
        var ostream = new System.IO.FileStream("debug.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write);
        var iStream = new System.IO.FileStream("input.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
        Console.SetIn(new System.IO.StreamReader(iStream));
        System.Diagnostics.Debug.AutoFlush = true;
        System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(new System.IO.StreamWriter(ostream, System.Text.Encoding.UTF8)));
        try
        {
#endif
            var solver = new Solver();
            solver.Solve();
#if DEBUG
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
        }
        Console.ReadKey(true);
#endif
    }
    _Scanner sc = new _Scanner();

}
static public class Printer
{
    static readonly private System.IO.TextWriter writer;
    static readonly private System.Globalization.CultureInfo info;
    static string Separator { get; set; }
    static Printer()
    {
        writer = Console.Out;
        info = System.Globalization.CultureInfo.InvariantCulture;
        Separator = " ";
    }

    static public void Print(int num) { writer.Write(num.ToString(info)); }
    static public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }
    static public void Print(long num) { writer.Write(num.ToString(info)); }
    static public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }
    static public void Print(double num) { writer.Write(num.ToString(info)); }
    static public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }
    static public void Print(string str) { writer.Write(str); }
    static public void Print(string format, params object[] arg) { writer.Write(format, arg); }
    static public void Print(IEnumerable<char> sources) { writer.Write(sources.AsString()); }
    static public void Print(params object[] arg)
    {
        var res = new System.Text.StringBuilder();
        foreach (var x in arg)
        {
            res.AppendFormat(info, "{0}", x);
            if (!string.IsNullOrEmpty(Separator))
                res.Append(Separator);
        }
        writer.Write(res.ToString(0, res.Length - Separator.Length));
    }
    static public void Print<T>(IEnumerable<T> sources)
    {
        var res = new System.Text.StringBuilder();
        foreach (var x in sources)
        {
            res.AppendFormat(info, "{0}", x);
            if (string.IsNullOrEmpty(Separator))
                res.Append(Separator);
        }
        writer.Write(res.ToString(0, res.Length - Separator.Length));
    }
    static public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }
    static public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }
    static public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }
    static public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }
    static public void PrintLine(double num) { writer.WriteLine(num.ToString(info)); }
    static public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }
    static public void PrintLine(string str) { writer.WriteLine(str); }
    static public void PrintLine(string format, params object[] arg) { writer.WriteLine(format, arg); }
    static public void PrintLine(IEnumerable<char> sources) { writer.WriteLine(sources.AsString()); }
    static public void PrintLine(params object[] arg)
    {
        var res = new System.Text.StringBuilder();
        foreach (var x in arg)
        {
            res.AppendFormat(info, "{0}", x);
            if (!string.IsNullOrEmpty(Separator))
                res.Append(Separator);
        }
        writer.WriteLine(res.ToString(0, res.Length - Separator.Length));
    }
    static public void PrintLine<T>(IEnumerable<T> sources)
    {
        var res = new System.Text.StringBuilder();
        foreach (var x in sources)
        {
            res.AppendFormat(info, "{0}", x);
            if (!string.IsNullOrEmpty(Separator))
                res.Append(Separator);
        }
        writer.WriteLine(res.ToString(0, res.Length - Separator.Length));
    }
}
public class _Scanner
{
    readonly private System.Globalization.CultureInfo info;
    readonly System.IO.TextReader reader;
    string[] buffer = new string[0];
    int position;

    public char[] Separator { get; set; }
    public _Scanner(System.IO.TextReader reader = null, string separator = null, System.Globalization.CultureInfo info = null)
    {

        this.reader = reader ?? Console.In;
        if (string.IsNullOrEmpty(separator))
            separator = " ";
        this.Separator = separator.ToCharArray();
        this.info = info ?? System.Globalization.CultureInfo.InvariantCulture;
    }
    public string Scan()
    {
        if (this.position < this.buffer.Length)
            return this.buffer[this.position++];
        this.buffer = this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        this.position = 0;
        return this.buffer[this.position++];
    }

    public string[] ScanToEndLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        var size = this.buffer.Length - this.position;
        var ar = new string[size];
        Array.Copy(this.buffer, position, ar, 0, size);
        return ar;

    }

    public string ScanLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine();
        else
        {
            var sb = new System.Text.StringBuilder();
            for (; this.position < buffer.Length; this.position++)
            {
                sb.Append(this.buffer[this.position]);
                sb.Append(' ');
            }
            return sb.ToString();
        }
    }
    public string[] ScanArray(int length)
    {
        var ar = new string[length];
        for (int i = 0; i < length; i++)
        {
            ar[i] = this.Scan();
        }
        return ar;
    }

    public int Integer()
    {
        return int.Parse(this.Scan(), info);
    }
    public long Long()
    {
        return long.Parse(this.Scan(), info);
    }
    public double Double()
    {
        return double.Parse(this.Scan(), info);
    }
    public double Double(string str)
    {
        return double.Parse(str, info);
    }

    public int[] IntArray(int length)
    {
        var a = new int[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Integer();
        return a;
    }
    public long[] LongArray(int length)
    {
        var a = new long[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Long();
        return a;
    }
    public double[] DoubleArray(int length)
    {
        var a = new double[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Double();
        return a;
    }

}
static public partial class EnumerableEx
{
    static public string AsString(this IEnumerable<char> source)
    {
        return new string(source.ToArray());
    }
    static public IEnumerable<T> Enumerate<T>(this int count, Func<int, T> selector)
    {
        return Enumerable.Range(0, count).Select(x => selector(x));
    }
}
 #region dice
    public class Dice
    {
        int[] d;
        public Dice(int[] dice)
        {
            d = dice;
        }
        public Dice RotationZ()
        {
            var u = d[1]; d[1] = d[2]; d[2] = d[4]; d[4] = d[3]; d[3] = u;
            return this;
        }
        public Dice RotationX()
        {
            var u = d[1]; d[1] = d[0]; d[0] = d[4]; d[4] = d[5]; d[5] = u;
            return this;
        }
        public Dice RotationY()
        {
            var u = d[0]; d[0] = d[2]; d[2] = d[5]; d[5] = d[3]; d[3] = u;
            return this;
        }
        public long AsLong()
        {
            long ret = 0;
            for (int i = 0; i < 6; i++)
                ret = ret * 26 + d[i];
            return ret;
        }
    }
#endregion
#region next_permutation
static public partial class MathEx
{

    static public bool NextPermutation<T>(this T[] array, int first, int last) where T : IComparable<T>
    {
        if (first == last)
            return false;
        var i = last;
        if (--i == first)
            return false;
        while (true)
        {
            var ii = i--;
            if (array[i].CompareTo(array[ii]) < 0)
            {
                var j = last;
                while (array[i].CompareTo(array[--j]) >= 0) { }
                var temp = array[i];
                array[i] = array[j];
                array[j] = temp;
                Array.Reverse(array, ii, last - ii);
                return true;
            }
            if (i == first)
            {
                Array.Reverse(array, first, last - first);
                return false;
            }
        }
    }

}
#endregion
//*/


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

namespace CodeForces.Solutions.c331_AbbyyCupFinal
{
	public class ProgramC
	{
		public static void Main()
		{
			checked
			{
			    var subs = new int[1000001];

			    for (int i = 1; i < subs.Length; i++)
			    {
			        subs[i] = int.MaxValue;
			        var tmp = i;
                    while (tmp > 0)
                    {
                        var d = tmp%10;
                        if (d != 0)
                            subs[i] = Math.Min(subs[i], subs[i - d] + 1);
                        tmp /= 10;
                    }
			    }

			    var n = long.Parse(Console.ReadLine());
			    Console.WriteLine(subs[n]);
			}
		}
	}
}


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

namespace task39D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] point1 = Console.ReadLine().Split();
            Int32 x1 = Int32.Parse(point1[0]);
            Int32 y1 = Int32.Parse(point1[1]);
            Int32 z1 = Int32.Parse(point1[2]);
            string[] point2 = Console.ReadLine().Split();
            Int32 x2 = Int32.Parse(point2[0]);
            Int32 y2 = Int32.Parse(point2[1]);
            Int32 z2 = Int32.Parse(point2[2]);
            if (Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)) - Math.Sqrt(2) <= 0.000001)
            {
                Console.WriteLine("YES");
            }
            else
                Console.WriteLine("NO");
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ProblemB
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var k = NN;
            var ary = new long[10];
            for (var i = 0; i < 10; i++)
            {
                ary[i] = 1;
            }
            var idx = 0;
            while (ary.Aggregate((x, y) => x * y) < k)
            {
                ++ary[idx];
                ++idx;
                if (idx == 10) idx = 0;
            }
            for (var i = 0; i < ary[0]; i++) Console.Write("c");
            for (var i = 0; i < ary[1]; i++) Console.Write("o");
            for (var i = 0; i < ary[2]; i++) Console.Write("d");
            for (var i = 0; i < ary[3]; i++) Console.Write("e");
            for (var i = 0; i < ary[4]; i++) Console.Write("f");
            for (var i = 0; i < ary[5]; i++) Console.Write("o");
            for (var i = 0; i < ary[6]; i++) Console.Write("r");
            for (var i = 0; i < ary[7]; i++) Console.Write("c");
            for (var i = 0; i < ary[8]; i++) Console.Write("e");
            for (var i = 0; i < ary[9]; i++) Console.Write("s");
            Console.WriteLine();
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
    class LIB_FastIO
    {
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[1024];
        int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        public LIB_FastIODebug() { }
        public override string Scan() => NextString();
        public override long Long() => long.Parse(NextString());
        public override double Double() => double.Parse(NextString());
    }
}


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

namespace Codeforces.NET
{
    class Table
    {
        List<List<char>> Components { get; set; }
    }
    class Program
    {
        private static void WriteFull(List<string> values)
        {
            for (int i = 0; i < 9; i++)
            {
                for(int j = 0; j < 9; j++)
                {
                    if (values[i][j] == '.')
                    {
                        Console.Write('!');
                    }
                    else Console.Write(values[i][j]);
                    if (j== 2 || j == 5)
                    {
                        Console.Write(' ');
                    }
                }
                if (i == 2 || i == 5)
                {
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            List<string> lines = new List<string>();
            string line = null;
            for (int i = 0; i < 11; i++)
            {
                line = Console.ReadLine();
                if (line != string.Empty)
                {
                    line = line.Replace(" ", "");
                    lines.Add(line);
                }
            }

            line = Console.ReadLine();
            int x = line.Split(' ').Select(xx => int.Parse(xx)).ToArray()[0];
            int y = line.Split(' ').Select(xx => int.Parse(xx)).ToArray()[1];

            int linie = x % 3;
            if (linie == 0) linie = 3;
            int coloana = y % 3;
            if (coloana == 0) coloana = 3;
            if (linie == 1 && coloana == 1)
            {
                bool isFull = true;
                for (int i = 1; i<=3; i++)
                {
                    for (int j = 1; j<=3; j++)
                    {
                        if (lines[i-1][j-1] == '.')
                        {
                            isFull = false;
                            break;
                        }
                    }
                }

                if (isFull)
                {
                    WriteFull(lines);
                    Console.ReadLine();
                    return;

                }

                for (int i = 1; i<=9; i++)
                {
                    for (int j = 1; j<=9; j++)
                    {
                        if (lines[i-1][j-1] != '.')
                        {
                            Console.Write(lines[i-1][j-1]);
                        }
                        else
                        {
                            if (i >= 1 && i <= 3 && j >= 1 && j <= 3)
                            {
                                Console.Write('!');
                            }
                            else Console.Write(lines[i - 1][j - 1]);
                        }
                        if (j == 3 || j == 6) Console.Write(' ');
                    }
                    if (i == 3 || i == 6) Console.WriteLine();
                    Console.WriteLine();
                }

                Console.ReadLine();
                return;
            }
            else if (linie == 1 && coloana == 2)
            {
                bool isFull = true;
                for (int i = 1; i <= 3; i++)
                {
                    for (int j = 4; j <= 6; j++)
                    {
                        if (lines[i - 1][j - 1] == '.')
                        {
                            isFull = false;
                            break;
                        }
                    }
                }
                if (isFull)
                {
                    WriteFull(lines);
                    Console.ReadLine();
                    return;

                }

                for (int i = 1; i <= 9; i++)
                {
                    for (int j = 1; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] != '.')
                        {
                            Console.Write(lines[i - 1][j - 1]);
                        }
                        else
                        {
                            if (i >= 1 && i <= 3 && j >= 4 && j <= 6)
                            {
                                Console.Write('!');
                            }
                            else Console.Write(lines[i - 1][j - 1]);

                        }
                        if (j == 3 || j == 6) Console.Write(' ');
                    }
                    if (i == 3 || i == 6)
                    {
                        Console.WriteLine();
                    }

                    Console.WriteLine();
                }

                Console.ReadLine();
                return;
            }
            else if (linie == 1 && coloana == 3)
            {
                bool isFull = true;
                for (int i = 1; i <= 3; i++)
                {
                    for (int j = 7; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] == '.')
                        {
                            isFull = false;
                            break;
                        }
                    }
                }
                if (isFull)
                {
                    WriteFull(lines);
                    Console.ReadLine();
                    return;

                }

                for (int i = 1; i <= 9; i++)
                {
                    for (int j = 1; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] != '.')
                        {
                            Console.Write(lines[i - 1][j - 1]);
                        }
                        else
                        {
                            if (i >= 1 && i <= 3 && j >= 7 && j <= 9)
                            {
                                Console.Write('!');
                            }
                            else Console.Write(lines[i - 1][j - 1]);

                        }
                        if (j == 3 || j == 6) Console.Write(' ');
                    }
                    if (i == 3 || i == 6) Console.WriteLine();

                    Console.WriteLine();
                }

                Console.ReadLine();
                return;
            }
            else if (linie == 2 && coloana == 1)
            {
                bool isFull = true;
                for (int i = 4; i <= 6; i++)
                {
                    for (int j = 1; j <= 3; j++)
                    {
                        if (lines[i - 1][j - 1] == '.')
                        {
                            isFull = false;
                            break;
                        }
                    }
                }
                if (isFull)
                {
                    WriteFull(lines);
                    Console.ReadLine();
                    return;

                }

                for (int i = 1; i <= 9; i++)
                {
                    for (int j = 1; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] != '.')
                        {
                            Console.Write(lines[i - 1][j - 1]);
                        }
                        else
                        {
                            if (i >= 4 && i <= 6 && j >= 1 && j <= 3)
                            {
                                Console.Write('!');
                            }
                            else Console.Write(lines[i - 1][j - 1]);
                        }
                        if (j == 3 || j == 6) Console.Write(' ');
                    }

                    if (i == 3 || i == 6) Console.WriteLine();

                    Console.WriteLine();
                }

                Console.ReadLine();
                return;
            }
            else if (linie == 2 && coloana == 2)
            {
                bool isFull = true;
                for (int i = 4; i <= 6; i++)
                {
                    for (int j = 4; j <= 6; j++)
                    {
                        if (lines[i - 1][j - 1] == '.')
                        {
                            isFull = false;
                            break;
                        }
                    }
                }
                if (isFull)
                {
                    WriteFull(lines);
                    Console.ReadLine();
                    return;

                }

                for (int i = 1; i <= 9; i++)
                {
                    for (int j = 1; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] != '.')
                        {
                            Console.Write(lines[i - 1][j - 1]);
                        }
                        else
                        {
                            if (i >= 4 && i <= 6 && j >= 4 && j <= 6)
                            {
                                Console.Write('!');
                            }
                            else Console.Write(lines[i - 1][j - 1]);
                        }
                        if (j == 3 || j == 6) Console.Write(' ');
                    }
                    if (i == 3 || i == 6) Console.WriteLine();

                    Console.WriteLine();
                }

                Console.ReadLine();
                return;
            }
            else if (linie == 2 && coloana == 3)
            {
                bool isFull = true;
                for (int i = 4; i <= 6; i++)
                {
                    for (int j = 7; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] == '.')
                        {
                            isFull = false;
                            break;
                        }
                    }
                }
                if (isFull)
                {
                    WriteFull(lines);
                    Console.ReadLine();
                    return;

                }

                for (int i = 1; i <= 9; i++)
                {
                    for (int j = 1; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] != '.')
                        {
                            Console.Write(lines[i - 1][j - 1]);
                        }
                        else
                        {
                            if (i >= 4 && i <= 6 && j >= 7 && j <= 9)
                            {
                                Console.Write('!');
                            }
                            else Console.Write(lines[i - 1][j - 1]);
                        }
                        if (j == 3 || j == 6) Console.Write(' ');
                    }
                    if (i == 3 || i == 6) Console.WriteLine();
                    Console.WriteLine();
                }

                Console.ReadLine();
                return;
            }
            else if (linie == 3 && coloana == 1)
            {
                bool isFull = true;
                for (int i = 7; i <= 9; i++)
                {
                    for (int j = 1; j <= 3; j++)
                    {
                        if (lines[i - 1][j - 1] == '.')
                        {
                            isFull = false;
                            break;
                        }
                    }
                }
                if (isFull)
                {
                    WriteFull(lines);
                    Console.ReadLine();
                    return;

                }

                for (int i = 1; i <= 9; i++)
                {
                    for (int j = 1; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] != '.')
                        {
                            Console.Write(lines[i - 1][j - 1]);
                        }
                        else
                        {
                            if (i >= 7 && i <= 9 && j >= 1 && j <= 3)
                            {
                                Console.Write('!');
                            }
                            else Console.Write(lines[i - 1][j - 1]);
                        }
                        if (j == 3 || j == 6) Console.Write(' ');
                    }
                    if (i == 3 || i == 6) Console.WriteLine();
                    Console.WriteLine();
                }

                Console.ReadLine();
                return;
            }
            else if (linie == 3 && coloana == 2)
            {
                bool isFull = true;
                for (int i = 7; i <= 9; i++)
                {
                    for (int j = 4; j <= 6; j++)
                    {
                        if (lines[i - 1][j - 1] == '.')
                        {
                            isFull = false;
                            break;
                        }
                    }
                }
                if (isFull)
                {
                    WriteFull(lines);
                    Console.ReadLine();
                    return;

                }

                for (int i = 1; i <= 9; i++)
                {
                    for (int j = 1; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] != '.')
                        {
                            Console.Write(lines[i - 1][j - 1]);
                        }
                        else
                        {
                            if (i >= 7 && i <= 9 && j >= 4 && j <= 6)
                            {
                                Console.Write('!');
                            }
                            else Console.Write(lines[i - 1][j - 1]);
                        }
                        if (j == 3 || j == 6) Console.Write(' ');
                    }
                    if (i == 3 || i == 6) Console.WriteLine();
                    Console.WriteLine();
                }

                Console.ReadLine();
                return;
            }
            else
            {
                bool isFull = true;
                for (int i = 7; i <= 9; i++)
                {
                    for (int j = 7; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] == '.')
                        {
                            isFull = false;
                            break;
                        }
                    }
                }
                if (isFull)
                {
                    WriteFull(lines);
                    Console.ReadLine();
                    return;

                }

                for (int i = 1; i <= 9; i++)
                {
                    for (int j = 1; j <= 9; j++)
                    {
                        if (lines[i - 1][j - 1] != '.')
                        {
                            Console.Write(lines[i - 1][j - 1]);
                        }
                        else
                        {
                            if (i >= 7 && i <= 9 && j >= 7 && j <= 9)
                            {
                                Console.Write('!');
                            }
                            else Console.Write(lines[i - 1][j - 1]);
                        }
                        if (j == 3 || j == 6) Console.Write(' ');
                    }
                    if (i == 3 || i == 6) Console.WriteLine();
                    Console.WriteLine();
                }

                Console.ReadLine();
                return;
            }
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
public class CodeForces
{
#if TEST
    // To set this go to Project -> Properties -> Build -> General -> Conditional compilation symbols: -> enter 'TEST' into text box.
    const bool testing = false;
#else
const bool testing = false;
#endif

    static void program(TextReader input)
    {
        //var n = int.Parse(input.ReadLine());
        var data = input.ReadLine().Split(' ').Select(int.Parse).ToList();
        if(data.Where(a => a==1).ToList().Count >= 1 || data.Where(a => a == 3).ToList().Count == 3 || data.Where(a => a == 2).ToList().Count >= 2 || (data.Where(a => a == 2).ToList().Count == 1 && data.Where(a => a == 4).ToList().Count == 2))
        {
            Console.WriteLine("YES");
        } else
        {
            Console.WriteLine("NO");
        }
    }

    public static void Main(string[] args)
    {
        if (!testing)
        { // set testing to false when submiting to codeforces
            program(Console.In); // write your program in 'program' function (its your new main !)
            return;
        }

        Console.WriteLine("Test Case(1) => expected :");
        Console.WriteLine("YES\n");
        Console.WriteLine("Test Case(1) => found    :");
        program(new StringReader("2 2 3\n"));
        Console.WriteLine();

        Console.WriteLine("Test Case(2) => expected :");
        Console.WriteLine("NO\n");
        Console.WriteLine("Test Case(2) => found    :");
        program(new StringReader("4 2 3\n"));
        Console.WriteLine();

    }
}