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

namespace _94D2C
{
    class Program
    {
        static void Main(string[] args)
        {
            char[,] doska = new char[8, 8];
            for (int i = 0; i < 8; i++)
            {
                string temp = Console.ReadLine();
                for (int j = 0; j < 8; j++)
                {
                    doska[j, i] = temp[j];
                }
            }
            bool f = hod(doska, 0, 7, 0);
            if (f)
            {
                Console.WriteLine("WIN");
            }
            else
            {
                Console.WriteLine("LOSE");
            }
            /*
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                    Console.Write(doska[i, j] + " ");
                Console.WriteLine();
            }
            */
            Console.ReadLine();
        }
        static bool hod(char[,] doska, int x, int y, int n)
        {
            bool f = false;
            if (n > 8)
                f = true;
            else
            {
                bool f1 = false, f2 = false, f3 = false, f4 = false, f5 = false, f6 = false, f7 = false, f8 = false, f9 = false;
                if (x > 0)
                {
                    if (y - n > 0)
                    {
                        if ((doska[x - 1, y - n] != 'S') && (doska[x - 1, y - n - 1] != 'S'))
                            f1 = hod(doska, x - 1, y, n + 1);
                    }
                    else
                    {
                        if (y - n - 1 > 0)
                        {
                            if (doska[x - 1, y - n ] != 'S')
                                f1 = hod(doska, x - 1, y, n + 1);
                        }
                        else
                        {
                            f1 = hod(doska, x - 1, y, n + 1);
                        }
                    }
                }

                if (x < 7)
                {
                    if (y - n > 0)
                    {
                        if ((doska[x + 1, y - n] != 'S') && (doska[x + 1, y - n - 1] != 'S'))
                            f2 = hod(doska, x + 1, y, n + 1);
                    }
                    else
                    {
                        if (y - n - 1 >0)
                        {
                            if (doska[x + 1, y - n] != 'S')
                                f2 = hod(doska, x + 1, y, n + 1);
                        }
                        else
                        {
                            f2 = hod(doska, x + 1, y, n + 1);
                        }
                    }
                }

                if (y < 7)
                {
                    if (y - n+1 > 0)
                    {
                        if ((doska[x , y - n+1] != 'S') && (doska[x , y - n] != 'S'))
                            f3 = hod(doska, x , y+1, n + 1);
                    }
                    else
                    {
                        if (y -  n  >= 0)
                        {
                            if (doska[x , y - n ] != 'S')
                                f3 = hod(doska, x , y+1, n + 1);
                        }
                        else
                        {
                            f3 = hod(doska, x , y+1, n + 1);
                        }
                    }
                }

                if (y > 0)
                {
                    if ( (y - n -1 < 7)&&(y-n-1>0))
                    {
                        if ((doska[x, y - n -1] != 'S') && (doska[x, y - n-2] != 'S'))
                            f4 = hod(doska, x, y - 1, n + 1);
                    }
                    else
                    {
                        if (y - n-1 >= 0)
                        {
                            if (doska[x , y - n-1] != 'S')
                                f4 = hod(doska, x, y - 1, n + 1);
                        }
                        else
                        {
                            f4 = hod(doska, x, y - 1, n + 1);
                        }
                    }
                }
                if ((x > 0) && (y > 0))
                {
                    if ((y - n - 1 < 8) && (y - n - 1 > 0))
                    {
                        if ((doska[x-1, y - n - 1] != 'S') && (doska[x-1, y - n - 2] != 'S'))
                            f5 = hod(doska, x-1, y - 1, n + 1);
                    }
                    else
                    {
                        if (y - n - 1 >= 0)
                        {
                            if (doska[x -1, y - n-1] != 'S')
                                f5 = hod(doska, x-1, y - 1, n + 1);
                        }
                        else
                        {
                            f5 = hod(doska, x-1, y - 1, n + 1);
                        }
                    }
                }

                if ((x > 0) && (y < 7))
                {
                    if (y - n + 1 > 0)
                    {
                        if ((doska[x-1, y - n + 1] != 'S') && (doska[x-1, y - n] != 'S'))
                            f6 = hod(doska, x-1, y + 1, n + 1);
                    }
                    else
                    {
                        if (y - n >= 0)
                        {
                            if (doska[x - 1, y - n] != 'S')
                                f6 = hod(doska, x-1, y + 1, n + 1);
                        }
                        else
                        {
                            f6 = hod(doska, x-1, y + 1, n + 1);
                        }
                    }
                }

                if ((x < 7) && (y > 0))
                {
                    if ((y - n - 1 >= 0) && (y - n - 2 >= 0))
                    {
                        if ((doska[x + 1, y - n - 1] != 'S') && (doska[x + 1, y - n - 2] != 'S'))
                            f7 = hod(doska, x+ 1, y - 1, n + 1);
                    }
                    else
                    {
                        if (y - n - 1 >= 0)
                        {
                            if (doska[x + 1, y - n - 1] != 'S')
                                f7 = hod(doska, x + 1, y - 1, n + 1);
                        }
                        else
                        {
                            f7 = hod(doska, x + 1, y - 1, n + 1);
                        }
                    }
                }

                if ((x < 7) && (y < 7))
                {
                    if (y - n + 1 > 0)
                    {
                        if ((doska[x + 1, y - n + 1] != 'S') && (doska[x + 1, y - n] != 'S'))
                            f8 = hod(doska, x + 1, y + 1, n + 1);
                    }
                    else
                    {
                        if (y - n+1 >= 0)
                        {
                            if (doska[x + 1, y - n+1] != 'S')
                                f8 = hod(doska, x + 1, y + 1, n + 1);
                        }
                        else
                        {
                            f8 = hod(doska, x + 1, y + 1, n + 1);
                        }
                    }
                }
                if (y - n >= 0)
                {
                    if (doska[x, y - n] != 'S')
                    {
                        f9 = hod(doska, x, y, n + 1);
                    }
                }
                else
                {
                    f9 = hod(doska, x, y, n + 1);
                }
                f = f1 || f2 || f3 || f4 || f5 || f6 || f7 || f8 || f9;
            }

            return f;
        }
    }
}


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

class Solver
{
	class Node
	{
		public char[,] board = new char[8, 8];

		public Node()
		{
		}

		public int mx;
		public int my;
		public int s;

		public Node Move(int x, int y)
		{
			if (x < 0 || x >= 8 || y < 0 || y >= 8)
				return null;
			if (board[x, y] == 'S')
				return null;

			var next = new Node();
			next.mx = x;
			next.my = y;
			next.board = new char[8,8];
			for (int xx = 0; xx < 8; xx++)
			{
				for (int yy = 6; yy >= 0; yy--)
				{
					if (this.board[xx, yy] == 'S')
					{
						if (xx == mx && yy + 1 == my)
							return null;
						next.board[xx, yy + 1] = 'S';
						s++;
					}
				}
			}
			return next;
		}
	}

	public void Solve()
	{
		var list = new List<Node>();
		var s = new Node();
		for (int y = 0; y < 8; y++)
		{
			var ss = CF.ReadLine();
			for (int x = 0; x < 8; x++)
			{
				s.board[x, y] = ss[x];
				if (ss[x] == 'S')
					s.s++;
			}
		}
		s.my = 7;
		s.mx = 0;
		list.Add(s);

		for (; ; )
		{
			if (list.Count == 0)
			{
				CF.WriteLine("LOSE");
				return;
			}

			var list2 = new List<Node>();

			foreach(var n in list)
			{
				for (int dx = -1; dx <= 1; dx++)
				{
					for (int dy = -1; dy <= 1; dy++)
					{
						var next = n.Move(n.mx + dx, n.my + dy);
						if (next == null)
							continue;

						if ( s.s == 0 || (next.mx==7&&next.my==0))
						{
							CF.WriteLine("WIN");
							return;
						}
						list2.Add(next);
					}
				}
			}

			list = list2;
		}
    }

	//  test
	static Utils CF = new Utils(new[]{
@"
.......A
........
........
........
........
........
........
M.......
",
 @"
.......A
........
........
........
........
........
SS......
M.......
",
 @"
.......A
........
........
........
........
.S......
S.......
MS......
"

    });
    #region test

    static void Main(string[] args)
    {
#if DEBUG
        for (int t=0;t<CF.TestCount;t++ )
        {
            CF.Test(t);
            new Solver().Solve();
        }
#else
        new Solver().Solve();
#endif
    }

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

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

        public int TestCount
        {
            get
            {
                return _test_input.Length;
            }
        }

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

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

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

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

        string[] _test_input;

        List<string> _lines;

#if DEBUG
        public Utils(string[] test_input)
        {
            _test_input = test_input;
        }
#else

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

    }

    #endregion
}


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

namespace Codeforces
{
    public class ProblemG568
    {
        static void Main(string[] args)
        {
            var nt = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = nt[0];
            int t = nt[1];
            var songs = new List<Tuple<int, int>>();
            int modulo = 1000000000 + 7;
            for (int i = 0; i < n; i++)
            {
                var ns = Console.ReadLine().Split().Select(int.Parse).ToArray();
                songs.Add(Tuple.Create(ns[0], ns[1]));
            }
            var playlists = new SortedDictionary<int, Dictionary<Tuple<int, int>, int>>();
            playlists.Add(0, new Dictionary<Tuple<int, int>, int>());
            playlists[0][Tuple.Create(0, -1)] = 1;
            int count = 0;
            while (playlists.Count > 0)
            {
                var kvp = playlists.First();
                int refTime = kvp.Key;
                if (refTime == t)
                {
                    // on compte
                    foreach (var kvp2 in kvp.Value)
                    {
                        count = (count + kvp2.Value) % modulo;
                    }
                    break;
                }
                else if (refTime > t)
                {
                    // too much
                    break;
                }

                playlists.Remove(refTime);
                foreach (var kvp2 in kvp.Value)
                {
                    int play = kvp2.Key.Item1;
                    int last = kvp2.Key.Item2;
                    int lastgenre = last == -1 ? -1 : songs[last].Item2;
                    int counting = kvp2.Value;
                    for (int i = 0; i < n; i++)
                    {
                        // not already played
                        if ((play & (1 << i)) > 0)
                            continue;
                        int nextplay = play | (1 << i);

                        // no two consecutive genre
                        if (songs[i].Item2 == lastgenre)
                            continue;
                        int nexttime = refTime + songs[i].Item1;
                        // playlist too long
                        if (nexttime > t)
                            continue;
                        if (!playlists.ContainsKey(nexttime))
                        {
                            playlists[nexttime] = new Dictionary<Tuple<int, int>, int>();
                        }
                        var nextkey = Tuple.Create(nextplay, i);
                        if (!playlists[nexttime].ContainsKey(nextkey))
                        {
                            playlists[nexttime][nextkey] = 0;
                        }
                        playlists[nexttime][nextkey] = (playlists[nexttime][nextkey] + counting) % modulo;
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

namespace codeforces
{

    public class Program
    {
        private const int NMax = 1000 * 1000 + 1;

        private static void Main(string[] args)
        {
            var values = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(values[0]);
            int m = Convert.ToInt32(values[1]);

            var f = new double[NMax];
            f[1] = Math.Log(1.0);
            for (int i = 2; i < NMax; ++i)
            {
                f[i] = f[i - 1] + Math.Log(i);
            }

            double result = 0.0;
            double p2 = f[n * m] - f[n] - f[n * m - n];
            int mn = Math.Min(n, m);
            for (int i = 1; i <= mn; ++i)
            {
                double p1 = 2 * Math.Log(i) - Math.Log(n);
                p1 += f[m] - f[i] - f[m - i];
                p1 += f[n * m - m] - f[n - i] - f[n * m - m - n + i];
                p1 -= p2;
                result += Math.Exp(p1);
            }
            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Debug = System.Diagnostics.Debug;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
namespace Solver
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var m = sc.Integer();
            if (n == 1)
                IO.Printer.Out.WriteLine("1.000000");
            else
            {
                double N = n;
                double M = m;
                var p = 1 / N;
                var q = (M - 1) / (N * M - 1);
                IO.Printer.Out.WriteLine(p+(1-p)*q);
            }
        }

        internal IO.StreamScanner sc;
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) a[i] = f(i); return a; }
    }

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

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

    }
    #endregion
}

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

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

    }
}
#endregion


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

public class Program
{
    int A, B, C, D;
    public void Solve()
    {
        var sc = new Scanner();
        A = sc.NextInt();
        B = sc.NextInt();
        C = sc.NextInt();
        D = sc.NextInt();

        // a<=x<=b<=y<=c<=z<=d なx,y,zな三角形がいくつか?

        // x+y = iのやついくつか?
        var st = new LazySegmentTree<long>((l, r) => l + r, 0, (l, r) => l * r, (l, r) => l + r, 0);
        for (int x = A; x <= B; x++)
        {
            int min = x + B;
            int max = x + C;
            st.Update(min, max + 1, 1);
        }
        long ans = 0;
        for (int z = C; z <= D; z++)
        {
            // x+y > z

            ans += st.Query(z + 1, B + C + 1);
        }
        Console.WriteLine(ans);
    }

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

namespace CompLib.Collections.Generic
{
    using System;

    public class LazySegmentTree<T>
    {
        private const int N = 1 << 20;
        private readonly T[] _array;
        private readonly T[] _tmp;
        private readonly bool[] _flag;

        private readonly T _identity, _updateIdentity;
        private readonly Func<T, T, T> _operation, _update;
        private readonly Func<T, int, T> _multiplication;

        /// <summary>
        /// コンストラクタ updateIdentityで初期化
        /// </summary>
        /// <param name="operation">区間演算用の演算</param>
        /// <param name="identity">(T, operation)の単位元</param>
        /// <param name="multiplication">(T, operation)のスカラー乗算</param>
        /// <param name="update">区間更新用の演算</param>
        /// <param name="updateIdentity">(T, update)の左単位元</param>
        public LazySegmentTree(Func<T, T, T> operation, T identity, Func<T, int, T> multiplication, Func<T, T, T> update,
            T updateIdentity)
        {
            _operation = operation;
            _identity = identity;
            _multiplication = multiplication;
            _update = update;
            _updateIdentity = updateIdentity;
            _array = new T[2 * N];
            for (int i = 0; i < N; i++)
            {
                _array[i + N] = _updateIdentity;
            }

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

            _tmp = new T[2 * N];
            for (int i = 1; i < 2 * N; i++)
            {
                _tmp[i] = _updateIdentity;
            }

            _flag = new bool[2 * N];
        }

        private void Eval(int k, int l, int r)
        {
            if (_flag[k])
            {
                if (r - l > 1)
                {
                    _tmp[k * 2] = _update(_tmp[k * 2], _tmp[k]);
                    _flag[k * 2] = true;
                    _tmp[k * 2 + 1] = _update(_tmp[k * 2 + 1], _tmp[k]);
                    _flag[k * 2 + 1] = true;
                }

                _array[k] = _update(_array[k], _multiplication(_tmp[k], r - l));
                _tmp[k] = _updateIdentity;
                _flag[k] = false;
            }
        }

        private void Update(int left, int right, int k, int l, int r, T n)
        {
            Eval(k, l, r);
            if (r <= left || right <= l) return;
            if (left <= l && r <= right)
            {
                // 本当は _update(tmp[k], n)だけど 上でEval()したので _tmp[k]は単位元
                _tmp[k] = n;
                _flag[k] = true;
                Eval(k, l, r);
            }
            else
            {
                Update(left, right, k * 2, l, (l + r) / 2, n);
                Update(left, right, k * 2 + 1, (l + r) / 2, r, n);
                _array[k] = _operation(_array[k * 2], _array[k * 2 + 1]);
            }
        }

        /// <summary>
        /// [left, right)をupdate(A[i], n)に更新する
        /// </summary>
        /// <param name="left">右端</param>
        /// <param name="right">左端</param>
        /// <param name="n">値</param>
        public void Update(int left, int right, T n) => Update(left, right, 1, 0, N, n);

        /// <summary>
        /// A[i]をupdate(A[i] ,n)に更新する
        /// </summary>
        /// <param name="i">index</param>
        /// <param name="n">値</param>
        public void Update(int i, T n) => Update(i, i + 1, n);

        private T Query(int left, int right, int k, int l, int r)
        {
            Eval(k, l, r);
            if (r <= left || right <= l) return _identity;
            if (left <= l && r <= right) return _array[k];
            return _operation(Query(left, right, k * 2, l, (l + r) / 2), Query(left, right, k * 2 + 1, (l + r) / 2, r));
        }

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

        public T this[int i]
        {
            get { return Query(i, i + 1); }
        }

        public T[] ToArray()
        {
            T[] result = new T[N];
            for (int i = 0; i < N; i++)
            {
                result[i] = this[i];
            }

            return result;
        }
    }
}

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

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

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

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

            return _line[_index++];
        }

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

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

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


using System;
using System.Collections.Generic;
using System.IO;
using System.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 CODEFORCES2
    {
        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 A = NN;
            var B = NN;
            var C = NN;
            var D = NN;
            var range = D - C + 1;
            var ans = 0L;
            for (var i = 0; i < range; i++)
            {
                var z = C + i;
                var miny = B;
                var needx = z - miny + 1;
                if (needx > B)
                {
                    var herasi = B - needx;
                    miny -= herasi;
                    if (miny > C)
                    {
                        continue;
                    }
                }
                var cntx = B - Max(A, needx) + 1;
                var nokoriacnt = (B - A + 1) - cntx + 1;
                var bcnt = C - B + 1;
                var mincnt = Min(nokoriacnt, bcnt);
                var s = mincnt * (2 * cntx + mincnt - 1) / 2;
                var nokorib = bcnt - mincnt;
                var thiscnt = s + nokorib * (B - A + 1);
                ans += thiscnt;
            }
            Console.WriteLine(ans);
        }
        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.Text;

namespace A.Theatre_Square
{
    class Program
    {

        static void Main(string[] args)
        {
            int data = Int32.Parse(Console.ReadLine().Trim());
            if (data == 0)
            {
                Console.WriteLine("0");
                return;
            }
            Int64 count = 0;
            Int64 n = (Int64)((Math.Sqrt((((double)data * data) - 0.5 * 0.5) / 0.75) + 1) / 2);
            count=3*n*n-3*n+1;

                Int64 need = 0;
                do
                {
                    double yy = (n + 0.5) * Math.Sqrt(3);
                    double xx = 0.5;
                    need = 0;
                    for (int i = 0; i < n + 1; i++)
                    {
                        double x = xx + 1.5 * i;
                        double y = yy - (double)i * Math.Sqrt(3)/2;
                        if (x * x + y * y - (double)data * data<10e-6)
                        {
                            need = (n + 1 - i * 2) < 0 ? 0 : (n + 1 - i * 2);
                            break;
                        }
                    }
                    count += need * 6;
                    n++;
                } while (need != 0);

            Console.WriteLine(count);

        }

    }
}


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

namespace A.Theatre_Square
{
    class Program
    {

        static void Main(string[] args)
        {
            int data = Int32.Parse(Console.ReadLine().Trim());
            if (data == 0)
            {
                Console.WriteLine("0");
                return;
            }
            Int64 count = 0;
            int n = (int)((Math.Sqrt(((double)(data * data) - 0.5 * 0.5) / 0.75) + 1) / 2);
            count=3*n*n-3*n+1;

                int need = 0;
                do
                {
                    double yy = (n + 0.5) * Math.Sqrt(3);
                    double xx = 0.5;
                    need = 0;
                    for (int i = 0; i < n + 1; i++)
                    {
                        double x = xx + 1.5 * i;
                        double y = yy - (double)i * Math.Sqrt(3)/2;
                        if (x * x + y * y - (double)data * data<10e-6)
                        {
                            need = (n + 1 - i * 2) < 0 ? 0 : (n + 1 - i * 2);
                            break;
                        }
                    }
                    count += need * 6;
                    n++;
                } while (need != 0);

            Console.WriteLine(count);

        }

    }
}


//

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

namespace sar_cs
{
    static class Helpers
    {
        public static string Join<T>(this IEnumerable<T> objs, string sep)
        {
            var sb = new StringBuilder();
            foreach (var s in objs) { if (sb.Length != 0) sb.Append(sep); sb.Append(s); }
            return sb.ToString();
        }

        public static string AsString(this double a, int digits)
        {
            return a.ToString("F" + digits, CultureInfo.InvariantCulture);
        }

        public static T[] Copy<T>(this T[] a)
        {
            var b = new T[a.Length]; a.CopyTo(b, 0); return b;
        }

        public static T[][] Copy<T>(this T[][] a)
        {
            return a.Select(z => z.Copy()).ToArray();
        }

        public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> collection)
        {
            if (collection.Take(11).Count() <= 10) return collection;
            var a = collection is T[] ? (T[])collection : collection.ToArray();
            int N = a.Length;
            for (int i = 0, p1 = 0, p2 = 1; i < N / 2; i++)
            {
                p1 += 3; if (p1 >= N) p1 -= N;
                p2 -= 7; if (p2 < 0) p2 += N;
                T t = a[p1]; a[p1] = a[p2]; a[p2] = t;
            }
            return a;
        }

        public static string AsString<T>(this T[,] a, string separator)
        {
            var sb = new StringBuilder();
            int n0 = a.GetLength(0);
            int n1 = a.GetLength(1);
            for (int r = 0; r < n0; r++)
            {
                for (int c = 0; c < n1; c++)
                {
                    if (c != 0) sb.Append(separator); sb.Append(a[r, c]);
                }
                sb.AppendLine();
            }
            //sb.AppendLine();
            return sb.ToString();
        }

        public static Stopwatch SW = Stopwatch.StartNew();
    }

    public class Program
    {
        #region Helpers

        public class Parser
        {
            const int BufSize = 8000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1; else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-') { sign = 1; c = Read(); }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-') { sign = 1; c = Read(); }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public int ReadLnInt()
            {
                int res = ReadInt(); ReadLine(); return res;
            }

            public long ReadLnLong()
            {
                long res = ReadLong(); ReadLine(); return res;
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-') { sign = -1; c = Read(); }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c); c = Read();
                }

                Back();
                var res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c); c = Read();
                }
                if (c == 13) { c = Read(); if (c != 10) Back(); }
                return sb.ToString();
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }

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

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

        class Writer
        {
            const int BufSize = 32000;
            char[] buf = new char[BufSize];
            int bufPos = 0;
            TextWriter output = Console.Out;
            Stack<char> st = new Stack<char>();

            public void Flush()
            {
                output.Write(buf, 0, bufPos); bufPos = 0;
                output.Flush();
            }

            void BufSpaceNeeded(int n)
            {
                if (n > BufSize) throw new ArgumentOutOfRangeException("n");
                if (bufPos + n > BufSize) { output.Write(buf, 0, bufPos); bufPos = 0; }
            }

            public void Write(char a)
            {
                BufSpaceNeeded(1);
                buf[bufPos++] = a;
            }

            public void Write(string s)
            {
                int l = s.Length;
                for (int x = 0; x < l; )
                {
                    int t = Math.Min(l - x, BufSize - bufPos);
                    s.CopyTo(x, buf, bufPos, t); bufPos += t; x += t;
                    if (x < l) BufSpaceNeeded(1);   // force flush
                }
            }

            public void WriteLine()
            {
                BufSpaceNeeded(2);
                buf[bufPos++] = '\r'; buf[bufPos++] = '\n';
            }

            public void Write(object o) { Write(o.ToString()); }

            public void Write(uint a)
            {
                BufSpaceNeeded(10);
                do { st.Push((char)(a % 10 + 48)); a /= 10; } while (a != 0);
                while (st.Count != 0) buf[bufPos++] = st.Pop();
            }

            public void Write(ulong a)
            {
                BufSpaceNeeded(20);
                do { st.Push((char)(a % 10 + 48)); a /= 10; } while (a != 0);
                while (st.Count != 0) buf[bufPos++] = st.Pop();
            }

            public void Write(int a)
            {
                BufSpaceNeeded(11);
                if (a < 0) { buf[bufPos++] = '-'; a = -a; }
                Write((uint)a);
            }

            public void Write(long a)
            {
                BufSpaceNeeded(21);
                if (a < 0) { buf[bufPos++] = '-'; a = -a; }
                Write((ulong)a);
            }

            public void Write(double a, int digits)
            {
                Write(a.AsString(digits));
            }

            public void WriteLine(int a) { Write(a); WriteLine(); }
            public void WriteLine(long a) { Write(a); WriteLine(); }
            public void WriteLine(uint a) { Write(a); WriteLine(); }
            public void WriteLine(ulong a) { Write(a); WriteLine(); }
            public void WriteLine(string s) { Write(s); WriteLine(); }
            public void WriteLine(object o) { Write(o); WriteLine(); }
        }

        static void pe() { Console.WriteLine("???"); Environment.Exit(0); }
        static void re() { throw new Exception(); }
        static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
        static int Sqr(int a) { return a * a; }
        static long SqrL(int a) { return (long)a * a; }
        static long Sqr(long a) { return a * a; }
        static double Sqr(double a) { return a * a; }
        static double Sqrt(double a) { return Math.Sqrt(a); }

        static StringBuilder sb = new StringBuilder();
        static Random rnd = new Random(5);

        #endregion Helpers

        const uint M = 1000000007;
        static uint[,] PROD = new uint[16, 16];

        static int h, w, k;
        static int wh1;
        static int predefined_colors;
        static int[] vertMasks;
        static uint result;
        static int[,] resultmap = new int[16, 16];

        static int[,] map;
        static int[] color_mapping_to, color_mapping_from;

        static uint DistinctMappingsCount(int from_count, int to_count)
        {
            if (from_count > to_count) throw new Exception();
            if (from_count < 1) throw new Exception();
            return /*k! / (k-max)! */ PROD[to_count - from_count + 1, to_count];
        }

        static void Per2(int y, int x, int vertmask)
        {
            if (y >= h)
            {
                var qwe = resultmap;

                uint t = 1;
                result += t;

                if (result >= M) result -= M;
                return;
            }

            int used = vertmask | vertMasks[x];
            for (int i = 1; i <= k; i++)
                if ((used >> i & 1) == 0)
                {
                    int mc = map[y, x];
                    if (mc != 0)
                    {
                        if (i != mc) continue;
                    }

                    vertMasks[x] |= (1 << i);
                    resultmap[y, x] = i;
                    if (x == w - 1) Per2(y + 1, 0, 0);
                    else Per2(y, x + 1, used | (1 << i));
                    resultmap[y, x] = 0;
                    vertMasks[x] &= ~(1 << i);
                }
        }

        static void Per(int y, int x, int max, int vertmask)
        {
            var qwe = resultmap;

            if (y >= h)
            {
                if (max < wh1) throw new Exception();
                if (max > k) throw new Exception();
                // wh1 <= max <= k

                //result += DistinctMappingsCount(max, k);

                if (k < predefined_colors) throw new Exception();
                if (max < predefined_colors) throw new Exception();
                uint t = DistinctMappingsCount(max - predefined_colors, k - predefined_colors);
                result += t;

                if (result >= M) result -= M;
                return;
            }

            int used = vertmask | vertMasks[x];
            for (int i = 1; i <= max + 1; i++)
                if (i <= k)
                    if ((used >> i & 1) == 0)
                    {
                        int mc = map[y, x];
                        bool mapping = false;

                        if (mc != 0)
                        {
                            if (color_mapping_from[mc] == 0 && color_mapping_to[i] == 0)
                            {
                                mapping = true;
                                color_mapping_from[mc] = i;
                                color_mapping_to[i] = mc;
                            }
                            else if (color_mapping_from[mc] == 0 && color_mapping_to[i] != 0)
                            {
                                continue; // color i already mapped to other color
                            }
                            else if (color_mapping_from[mc] != 0 && color_mapping_to[i] == 0)
                            {
                                continue; // color mc already mapped from other color
                            }
                            else if (color_mapping_from[mc] != 0 && color_mapping_to[i] != 0)
                            {
                            }
                        }

                        vertMasks[x] |= (1 << i);
                        resultmap[y, x] = i;
                        if (x == w - 1) Per(y + 1, 0, Math.Max(i, max), 0);
                        else Per(y, x + 1, Math.Max(i, max), used | (1 << i));
                        resultmap[y, x] = 0;
                        vertMasks[x] &= ~(1 << i);

                        if (mapping)
                        {
                            color_mapping_to[i] = 0;
                            color_mapping_from[mc] = 0;
                        }

                    }
        }

        static void Main()
        {
            checked
            {
#if !ONLINE_JUDGE
                Console.SetIn(File.OpenText("_input"));
#endif
                //Console.SetOut(File.CreateText("_output"));
                var parser = new Parser();
                var o = new Writer();
                try
                {
                    for (uint i = 0; i < 16; i++)
                        for (uint j = 0; j < 16; j++)
                        {
                            if (j + 1 < i) PROD[i, j] = 0;
                            else if (j < i) PROD[i, j] = 1;
                            else if (j == i) PROD[i, j] = i;
                            else PROD[i, j] = (uint)(PROD[i, j - 1] * (ulong)j % M);
                        }

                    while (!parser.SeekEOF)
                    {
                        h = parser.ReadInt();
                        w = parser.ReadInt();
                        k = parser.ReadInt();
                        wh1 = w + h - 1;

                        map = new int[16, 16];

                        for (int y = 0; y < h; y++)
                            for (int x = 0; x < w; x++)
                                if (y < 16 && x < 16) map[y, x] = parser.ReadInt();
                                else parser.ReadInt();

                        //var mapping = new int[16];
                        //for (int y = 0; y < h; y++)
                        //    for (int x = 0; x < w; x++)
                        //    {
                        //        for (int color = 1; ; color++)
                        //        {
                        //            for (int y = 0; y < h; y++)
                        //                for (int x = 0; x < w; x++) { }
                        //        }
                        //    }

                        result = 0;
                        if (wh1 > k)
                        {
                        }
                        else
                        {
                            predefined_colors = map.Cast<int>().Where(c => c != 0).Distinct().Count();
                            color_mapping_from = new int[16];
                            color_mapping_to = new int[16];
                            vertMasks = new int[16];
                            Per(0, 0, 0, 0);
                            //o.WriteLine(result); result = 0;

                            //color_mapping_from = new int[16];
                            //color_mapping_to = new int[16];
                            //vertMasks = new int[16];
                            //Per2(0, 0, 0);
                        }

                        o.WriteLine(result);
                    }
                }
                finally
                {
                    o.Flush();
                }
            }
        }

        //static void Main()
        //{
        //    new Thread(Main2, 50 << 20).Start();
        //}
    }
}


//

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

namespace sar_cs
{
    static class Helpers
    {
        public static string Join<T>(this IEnumerable<T> objs, string sep)
        {
            var sb = new StringBuilder();
            foreach (var s in objs) { if (sb.Length != 0) sb.Append(sep); sb.Append(s); }
            return sb.ToString();
        }

        public static string AsString(this double a, int digits)
        {
            return a.ToString("F" + digits, CultureInfo.InvariantCulture);
        }

        public static T[] Copy<T>(this T[] a)
        {
            var b = new T[a.Length]; a.CopyTo(b, 0); return b;
        }

        public static T[][] Copy<T>(this T[][] a)
        {
            return a.Select(z => z.Copy()).ToArray();
        }

        public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> collection)
        {
            if (collection.Take(11).Count() <= 10) return collection;
            var a = collection is T[] ? (T[])collection : collection.ToArray();
            int N = a.Length;
            for (int i = 0, p1 = 0, p2 = 1; i < N / 2; i++)
            {
                p1 += 3; if (p1 >= N) p1 -= N;
                p2 -= 7; if (p2 < 0) p2 += N;
                T t = a[p1]; a[p1] = a[p2]; a[p2] = t;
            }
            return a;
        }

        public static string AsString<T>(this T[,] a, string separator)
        {
            var sb = new StringBuilder();
            int n0 = a.GetLength(0);
            int n1 = a.GetLength(1);
            for (int r = 0; r < n0; r++)
            {
                for (int c = 0; c < n1; c++)
                {
                    if (c != 0) sb.Append(separator); sb.Append(a[r, c]);
                }
                sb.AppendLine();
            }
            //sb.AppendLine();
            return sb.ToString();
        }

        public static Stopwatch SW = Stopwatch.StartNew();
    }

    public class Program
    {
        #region Helpers

        public class Parser
        {
            const int BufSize = 8000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1; else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-') { sign = 1; c = Read(); }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-') { sign = 1; c = Read(); }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public int ReadLnInt()
            {
                int res = ReadInt(); ReadLine(); return res;
            }

            public long ReadLnLong()
            {
                long res = ReadLong(); ReadLine(); return res;
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-') { sign = -1; c = Read(); }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c); c = Read();
                }

                Back();
                var res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c); c = Read();
                }
                if (c == 13) { c = Read(); if (c != 10) Back(); }
                return sb.ToString();
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }

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

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

        class Writer
        {
            const int BufSize = 32000;
            char[] buf = new char[BufSize];
            int bufPos = 0;
            TextWriter output = Console.Out;
            Stack<char> st = new Stack<char>();

            public void Flush()
            {
                output.Write(buf, 0, bufPos); bufPos = 0;
                output.Flush();
            }

            void BufSpaceNeeded(int n)
            {
                if (n > BufSize) throw new ArgumentOutOfRangeException("n");
                if (bufPos + n > BufSize) { output.Write(buf, 0, bufPos); bufPos = 0; }
            }

            public void Write(char a)
            {
                BufSpaceNeeded(1);
                buf[bufPos++] = a;
            }

            public void Write(string s)
            {
                int l = s.Length;
                for (int x = 0; x < l; )
                {
                    int t = Math.Min(l - x, BufSize - bufPos);
                    s.CopyTo(x, buf, bufPos, t); bufPos += t; x += t;
                    if (x < l) BufSpaceNeeded(1);   // force flush
                }
            }

            public void WriteLine()
            {
                BufSpaceNeeded(2);
                buf[bufPos++] = '\r'; buf[bufPos++] = '\n';
            }

            public void Write(object o) { Write(o.ToString()); }

            public void Write(uint a)
            {
                BufSpaceNeeded(10);
                do { st.Push((char)(a % 10 + 48)); a /= 10; } while (a != 0);
                while (st.Count != 0) buf[bufPos++] = st.Pop();
            }

            public void Write(ulong a)
            {
                BufSpaceNeeded(20);
                do { st.Push((char)(a % 10 + 48)); a /= 10; } while (a != 0);
                while (st.Count != 0) buf[bufPos++] = st.Pop();
            }

            public void Write(int a)
            {
                BufSpaceNeeded(11);
                if (a < 0) { buf[bufPos++] = '-'; a = -a; }
                Write((uint)a);
            }

            public void Write(long a)
            {
                BufSpaceNeeded(21);
                if (a < 0) { buf[bufPos++] = '-'; a = -a; }
                Write((ulong)a);
            }

            public void Write(double a, int digits)
            {
                Write(a.AsString(digits));
            }

            public void WriteLine(int a) { Write(a); WriteLine(); }
            public void WriteLine(long a) { Write(a); WriteLine(); }
            public void WriteLine(uint a) { Write(a); WriteLine(); }
            public void WriteLine(ulong a) { Write(a); WriteLine(); }
            public void WriteLine(string s) { Write(s); WriteLine(); }
            public void WriteLine(object o) { Write(o); WriteLine(); }
        }

        static void pe() { Console.WriteLine("???"); Environment.Exit(0); }
        static void re() { throw new Exception(); }
        static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
        static int Sqr(int a) { return a * a; }
        static long SqrL(int a) { return (long)a * a; }
        static long Sqr(long a) { return a * a; }
        static double Sqr(double a) { return a * a; }
        static double Sqrt(double a) { return Math.Sqrt(a); }

        static StringBuilder sb = new StringBuilder();
        static Random rnd = new Random(5);

        #endregion Helpers

        const uint M = 1000000007;
        static uint[,] PROD = new uint[16, 16];

        static int h, w, k;
        static int wh1;
        static int predefined_colors;
        static int[] vertMasks;
        static uint result;
        static int[,] resultmap = new int[16, 16];

        static int[,] map;
        static int[] color_mapping_to, color_mapping_from;

        static uint DistinctMappingsCount(int from_count, int to_count)
        {
            if (from_count > to_count) throw new Exception();
            if (from_count < 0) throw new Exception();
            return /*k! / (k-max)! */ PROD[to_count - from_count + 1, to_count];
        }

        static void Per2(int y, int x, int vertmask)
        {
            if (y >= h)
            {
                var qwe = resultmap;

                uint t = 1;
                result += t;

                if (result >= M) result -= M;
                return;
            }

            int used = vertmask | vertMasks[x];
            for (int i = 1; i <= k; i++)
                if ((used >> i & 1) == 0)
                {
                    int mc = map[y, x];
                    if (mc != 0)
                    {
                        if (i != mc) continue;
                    }

                    vertMasks[x] |= (1 << i);
                    resultmap[y, x] = i;
                    if (x == w - 1) Per2(y + 1, 0, 0);
                    else Per2(y, x + 1, used | (1 << i));
                    resultmap[y, x] = 0;
                    vertMasks[x] &= ~(1 << i);
                }
        }

        static void Per(int y, int x, int max, int vertmask)
        {
            var qwe = resultmap;

            if (y >= h)
            {
                if (max < wh1) throw new Exception();
                if (max > k) throw new Exception();
                // wh1 <= max <= k

                //result += DistinctMappingsCount(max, k);

                if (k < predefined_colors) throw new Exception();
                if (max < predefined_colors) throw new Exception();
                uint t = DistinctMappingsCount(max - predefined_colors, k - predefined_colors);
                result += t;

                if (result >= M) result -= M;
                return;
            }

            int used = vertmask | vertMasks[x];
            for (int i = 1; i <= max + 1; i++)
                if (i <= k)
                    if ((used >> i & 1) == 0)
                    {
                        int mc = map[y, x];
                        bool mapping = false;

                        if (mc != 0)
                        {
                            if (color_mapping_from[mc] == 0 && color_mapping_to[i] == 0)
                            {
                                mapping = true;
                                color_mapping_from[mc] = i;
                                color_mapping_to[i] = mc;
                            }
                            else if (color_mapping_from[mc] == 0 && color_mapping_to[i] != 0)
                            {
                                continue; // color i already mapped to other color
                            }
                            else if (color_mapping_from[mc] != 0 && color_mapping_to[i] == 0)
                            {
                                continue; // color mc already mapped from other color
                            }
                            else if (color_mapping_from[mc] != 0 && color_mapping_to[i] != 0)
                            {
                                if (color_mapping_to[i] != mc) continue;
                                if (color_mapping_from[mc] != i) throw new Exception();
                            }
                        }

                        vertMasks[x] |= (1 << i);
                        resultmap[y, x] = i;
                        if (x == w - 1) Per(y + 1, 0, Math.Max(i, max), 0);
                        else Per(y, x + 1, Math.Max(i, max), used | (1 << i));
                        resultmap[y, x] = 0;
                        vertMasks[x] &= ~(1 << i);

                        if (mapping)
                        {
                            color_mapping_to[i] = 0;
                            color_mapping_from[mc] = 0;
                        }

                    }
        }

        static void Main()
        {
            checked
            {
#if !ONLINE_JUDGE
                Console.SetIn(File.OpenText("_input"));
#endif
                //Console.SetOut(File.CreateText("_output"));
                var parser = new Parser();
                var o = new Writer();
                try
                {
                    for (uint i = 0; i < 16; i++)
                        for (uint j = 0; j < 16; j++)
                        {
                            if (j + 1 < i) PROD[i, j] = 0;
                            else if (j < i) PROD[i, j] = 1;
                            else if (j == i) PROD[i, j] = i;
                            else PROD[i, j] = (uint)(PROD[i, j - 1] * (ulong)j % M);
                        }

                    while (!parser.SeekEOF)
                    {
                        h = parser.ReadInt();
                        w = parser.ReadInt();
                        k = parser.ReadInt();
                        wh1 = w + h - 1;

                        map = new int[16, 16];

                        for (int y = 0; y < h; y++)
                            for (int x = 0; x < w; x++)
                                if (y < 16 && x < 16) map[y, x] = parser.ReadInt();
                                else parser.ReadInt();

                        //var mapping = new int[16];
                        //for (int y = 0; y < h; y++)
                        //    for (int x = 0; x < w; x++)
                        //    {
                        //        for (int color = 1; ; color++)
                        //        {
                        //            for (int y = 0; y < h; y++)
                        //                for (int x = 0; x < w; x++) { }
                        //        }
                        //    }

                        result = 0;
                        if (wh1 > k)
                        {
                        }
                        else
                        {
                            predefined_colors = map.Cast<int>().Where(c => c != 0).Distinct().Count();
                            color_mapping_from = new int[16];
                            color_mapping_to = new int[16];
                            vertMasks = new int[16];
                            Per(0, 0, 0, 0);
                            //o.WriteLine(result); result = 0;

                            //color_mapping_from = new int[16];
                            //color_mapping_to = new int[16];
                            //vertMasks = new int[16];
                            //Per2(0, 0, 0);
                        }

                        o.WriteLine(result);
                    }
                }
                finally
                {
                    o.Flush();
                }
            }
        }

        //static void Main()
        //{
        //    new Thread(Main2, 50 << 20).Start();
        //}
    }
}


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

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

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

            var info = CultureInfo.CurrentCulture;
            var nmk = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();
            var n = nmk[0];
            var k = nmk[2];

            var a = new int[n][];
            for (int i = 0; i < n; ++i)
            {
                a[i] = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();
            }

            var res = Calc(k, a);

            tw.WriteLine(res);
        }

        private static long Calc(int k, int[][] a)
        {
            var n = a.Length;
            var m = a[0].Length;

            if (k < n + m - 1)
            {
                return 0;
            }

            var p = new int[n * m];

            var patterns = new List<int[]>();
            CreatePatterns(ref patterns, 1, 0, 0, n, m, k, ref p);

            var res = 0L;

            foreach (var pattern in patterns)
            {
                if (!IsInvalid(pattern, a))
                {
                    var fixedCells = a.SelectMany(x => x).Where(x => x > 0).Distinct().Count();
                    res = (res + Permutation(k - fixedCells, pattern.Distinct().Count() - fixedCells)) % 1000000007;
                }
            }

            return res;
        }

        private static bool IsInvalid(int[] pattern, int[][] a)
        {
            var n = a.Length;
            var m = a[0].Length;

            var colorMap = new Dictionary<int, int>();
            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < m; ++j)
                {
                    if (a[i][j] > 0)
                    {
                        if (!colorMap.ContainsKey(a[i][j]))
                        {
                            foreach (var p in colorMap.Values)
                            {
                                if (p == pattern[i * m + j])
                                {
                                    return true;
                                }
                            }

                            colorMap[a[i][j]] = pattern[i * m + j];
                        }
                        else
                        {
                            if (colorMap[a[i][j]] != pattern[i * m + j])
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }

        private static int Permutation(int n, int k)
        {
            var res = 1;
            for (int i = 0; i < k; ++i)
            {
                res *= n - i;
            }
            return res;
        }

        private static void CreatePatterns(ref List<int[]> patterns, int newColor, int r, int c, int n, int m, int k, ref int[] board)
        {
            if (r == n)
            {
                patterns.Add(board.Clone() as int[]);
                return;
            }

            if (c == m)
            {
                CreatePatterns(ref patterns, newColor, r + 1, 0, n, m, k, ref board);
                return;
            }

            if (newColor > k)
            {
                return;
            }

            var used = new bool[newColor];

            for (int i = 0; i <= r; ++i)
            {
                for (int j = 0; j <= c; ++j)
                {
                    if (!(i == r && j == c))
                    {
                        used[board[i * m + j]] = true;
                    }
                }
            }

            for (int currentColor = 1; currentColor < newColor; ++currentColor)
            {
                if (!used[currentColor])
                {
                    board[r * m + c] = currentColor;
                    CreatePatterns(ref patterns, newColor, r, c + 1, n, m, k, ref board);
                    board[r * m + c] = 0;
                }
            }
            board[r * m + c] = newColor;
            CreatePatterns(ref patterns, newColor + 1, r, c + 1, n, m, k, ref board);
            board[r * m + c] = 0;
        }
    }
}


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

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

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

            var info = CultureInfo.CurrentCulture;
            var nmk = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();
            var n = nmk[0];
            var k = nmk[2];

            var a = new int[n][];
            for (int i = 0; i < n; ++i)
            {
                a[i] = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();
            }

            var res = Calc(k, a);

            tw.WriteLine(res);
        }

        private static int Calc(int k, int[][] a)
        {
            var n = a.Length;
            var m = a[0].Length;

            if (k < n + m - 1)
            {
                return 0;
            }

            var p = new int[n * m];

            var patterns = new List<int[]>();
            CreatePatterns(ref patterns, 1, 0, 0, n, m, k, ref p);

            var res = 0;

            foreach (var pattern in patterns)
            {
                if (!IsInvalid(pattern, a))
                {
                    var fixedCells = a.SelectMany(x => x).Where(x => x > 0).Distinct().Count();
                    res += Permutation(k - fixedCells, pattern.Distinct().Count() - fixedCells);
                }
            }

            return res;
        }

        private static bool IsInvalid(int[] pattern, int[][] a)
        {
            var n = a.Length;
            var m = a[0].Length;

            var colorMap = new Dictionary<int, int>();
            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < m; ++j)
                {
                    if (a[i][j] > 0)
                    {
                        if (!colorMap.ContainsKey(a[i][j]))
                        {
                            colorMap[a[i][j]] = i * m + j;
                        }
                        else
                        {
                            var prev = colorMap[a[i][j]];
                            var prevJ = prev % m;

                            if (prevJ <= j)
                            {
                                return true;
                            }

                            colorMap[a[i][j]] = i * m + j;

                            if (pattern[i * m + j] != pattern[prev])
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }

        private static int Permutation(int n, int k)
        {
            var res = 1;
            for (int i = 0; i < k; ++i)
            {
                res *= n - i;
            }
            return res;
        }

        private static void CreatePatterns(ref List<int[]> patterns, int newColor, int r, int c, int n, int m, int k, ref int[] board)
        {
            if (r == n)
            {
                patterns.Add(board.Clone() as int[]);
                return;
            }

            if (c == m)
            {
                CreatePatterns(ref patterns, newColor, r + 1, 0, n, m, k, ref board);
                return;
            }

            if (newColor > k)
            {
                return;
            }

            var used = new bool[newColor];

            for (int i = 0; i <= r; ++i)
            {
                for (int j = 0; j <= c; ++j)
                {
                    if (!(i == r && j == c))
                    {
                        used[board[i * m + j]] = true;
                    }
                }
            }

            for (int currentColor = 1; currentColor < newColor; ++currentColor)
            {
                if (!used[currentColor])
                {
                    board[r * m + c] = currentColor;
                    CreatePatterns(ref patterns, newColor, r, c + 1, n, m, k, ref board);
                    board[r * m + c] = 0;
                }
            }
            board[r * m + c] = newColor;
            CreatePatterns(ref patterns, newColor + 1, r, c + 1, n, m, k, ref board);
            board[r * m + c] = 0;
        }
    }
}