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

namespace CodeForces
{
	internal class B
	{
		private int MOD = 1000000007;
		private int n;
		private long m;
		private int k;
		private int[,] dp;
		private bool[,] was;
		private int[,] bin, pw;

		int go( int pos, int k )
		{
			if ( pos == n )
			{
				if ( k == 0 ) return 1;
				return 0;
			}
			if ( was[pos, k] )
				return dp[pos, k];
			int res = go( pos + 1, k );

			for ( int i = 1; i <= n && i <= k; ++i )
			{
				int tmp = (int)( ( (long)pw[pos, i] * go( pos + 1, k - i ) ) % MOD );
				res += tmp;
				if ( res >= MOD ) res -= MOD;
			}

			was[pos, k] = true;
			return dp[pos, k] = res;
		}

		private int pow( int a, long b )
		{
			if ( b == 0 ) return 1;
			int tmp = pow( a, b / 2 );
			tmp = (int)( ( (long)tmp * tmp ) % MOD );
			if ( b % 2 == 1 )
			{
				tmp = (int)( ( (long)tmp * a ) % MOD );
			}
			return tmp;
		}

		private void Solve()
		{
			n = NextInt();
			m = NextLong();
			k = NextInt();

			bin = new int[101, 101];
			for ( int i = 0; i <= 100; ++i )
			{
				bin[i, 0] = bin[i, i] = 1;
				for ( int j = 1; j < i; ++j ) bin[i, j] = ( bin[i - 1, j] + bin[i - 1, j - 1] ) % MOD;
			}
			pw = new int[101, 101];
			for ( int pos = 0; pos < n; ++pos )
			{
				long cnt = ( ( ( m - pos ) % n ) == 0 ? ( m - pos ) / n - 1 : ( m - pos ) / n ) + 1;
				for ( int i = 1; i <= n; ++i )
				{
					pw[pos, i] = pow( bin[n, i], cnt );
				}
			}

			dp = new int[n, n * n + 1];
			was = new bool[n, n * n + 1];
			Out.WriteLine( go( 0, k ) );
		}

		#region Local wireup

		public int NextInt()
		{
			return _in.NextInt();
		}

		public long NextLong()
		{
			return _in.NextLong();
		}

		public string NextLine()
		{
			return _in.NextLine();
		}

		public double NextDouble()
		{
			return _in.NextDouble();
		}

		readonly Scanner _in = new Scanner();
		static readonly TextWriter Out = Console.Out;

		void Start()
		{
#if !ONLINE_JUDGE
			var timer = new Stopwatch();
			timer.Start();
#endif
			var t = new Thread( Solve, 20000000 );
			t.Start();
			t.Join();
#if !ONLINE_JUDGE
			timer.Stop();
			Console.WriteLine( string.Format( CultureInfo.InvariantCulture, "Done in {0} seconds.\nPress <Enter> to exit.", timer.ElapsedMilliseconds / 1000.0 ) );
			Console.ReadLine();
#endif
		}

		static void Main()
		{
			new B().Start();
		}

		class Scanner : IDisposable
		{
			#region Fields

			readonly TextReader _reader;
			readonly int _bufferSize;
			readonly bool _closeReader;
			readonly char[] _buffer;
			int _length, _pos;

			#endregion

			#region .ctors

			public Scanner( TextReader reader, int bufferSize, bool closeReader )
			{
				_reader = reader;
				_bufferSize = bufferSize;
				_closeReader = closeReader;
				_buffer = new char[_bufferSize];
				FillBuffer( false );
			}

			public Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }

			public Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }

#if ONLINE_JUDGE
			public Scanner() : this( Console.In, false ) { }
#else
			public Scanner() : this( "input.txt" ) { }
#endif

			#endregion

			#region IDisposable Members

			public void Dispose()
			{
				if ( _closeReader )
				{
					_reader.Close();
				}
			}

			#endregion

			#region Properties

			public bool Eof
			{
				get
				{
					if ( _pos < _length ) return false;
					FillBuffer( false );
					return _pos >= _length;
				}
			}

			#endregion

			#region Methods

			private char NextChar()
			{
				if ( _pos < _length ) return _buffer[_pos++];
				FillBuffer( true );
				return _buffer[_pos++];
			}

			private char PeekNextChar()
			{
				if ( _pos < _length ) return _buffer[_pos];
				FillBuffer( true );
				return _buffer[_pos];
			}

			private void FillBuffer( bool throwOnEof )
			{
				_length = _reader.Read( _buffer, 0, _bufferSize );
				if ( throwOnEof && Eof )
				{
					throw new IOException( "Can't read beyond the end of file" );
				}
				_pos = 0;
			}

			public int NextInt()
			{
				var neg = false;
				int res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public long NextLong()
			{
				var neg = false;
				long res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public string NextLine()
			{
				SkipUntilNextLine();
				if ( Eof ) return "";
				var builder = new StringBuilder();
				while ( !Eof && !IsEndOfLine( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return builder.ToString();
			}

			public double NextDouble()
			{
				SkipWhitespaces();
				var builder = new StringBuilder();
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return double.Parse( builder.ToString(), CultureInfo.InvariantCulture );
			}

			private void SkipWhitespaces()
			{
				while ( !Eof && IsWhitespace( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private void SkipUntilNextLine()
			{
				while ( !Eof && IsEndOfLine( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private static bool IsWhitespace( char c )
			{
				return c == ' ' || c == '\t' || c == '\n' || c == '\r';
			}

			private static bool IsEndOfLine( char c )
			{
				return c == '\n' || c == '\r';
			}

			#endregion
		}

		#endregion
	}
}


using System;

public sealed class Program {

  const Int64 Mod = 1000000007;

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

  public Program () {
    Int32 n = ReadInt(), cap = ReadInt(), i, cnt50 = 0, cnt100 = 0, a, b, c, d;
    for (i = 0; i < n; ++i) {
      if (ReadInt() == 50) {
        ++cnt50;
      } else {
        ++cnt100;
      }
    }
    Int64[,] binomial = new Int64[n + 1, n + 1];
    for (i = 0; i <= n; ++i) {
      binomial[i, 0] = binomial[i, i] = 1;
    }
    for (a = 2; a <= n; ++a) {
      for (b = 1; b < a; ++b) {
        binomial[a, b] = (binomial[a - 1, b] + binomial[a - 1, b - 1]) % Mod;
      }
    }
    Int64[, ,] dp = new Int64[n * 2 + 1, cnt50 + 1, cnt100 + 1];
    dp[0, cnt50, cnt100] = 1;
    for (i = 0; ; ++i) {
      if (i == n * 2) {
        Console.WriteLine(-1);
        Console.WriteLine('0');
        break;
      } else if (i % 2 != 0 && dp[i, cnt50, cnt100] != 0) {
        Console.WriteLine(i);
        Console.WriteLine(dp[i, cnt50, cnt100]);
        break;
      }
      for (a = 0; a <= cnt50; ++a) {
        for (b = 0; b <= cnt100; ++b) {
          if (dp[i, a, b] != 0) {
            for (c = 0; c <= a; ++c) {
              for (d = 0; d <= b && c * 50 + d * 100 <= cap; ++d) {
                if (c + d != 0) {
                  Add(ref dp[i + 1, cnt50 - (a - c), cnt100 - (b - d)], dp[i, a, b] * binomial[a, c] % Mod * binomial[b, d] % Mod);
                }
              }
            }
          }
        }
      }
    }
  }

  // stuff cutline

  public static void Main() {
#if DEBUG
    Console.SetIn(new System.IO.StreamReader("..\\..\\in.txt"));
#endif
    var root = new Program();
    Console.Out.Flush();
  }

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

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

}


using System;

public sealed class Program {

  const Int64 Mod = 1000000007;

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

  public Program () {
    Int32 n = ReadInt(), cap = ReadInt(), i, cnt50 = 0, cnt100 = 0, a, b, c, d;
    for (i = 0; i < n; ++i) {
      if (ReadInt() == 50) {
        ++cnt50;
      } else {
        ++cnt100;
      }
    }
    Int64[,] binomial = new Int64[n + 1, n + 1];
    for (i = 0; i <= n; ++i) {
      binomial[i, 0] = binomial[i, i] = 1;
    }
    for (a = 2; a <= n; ++a) {
      for (b = 1; b < a; ++b) {
        binomial[a, b] = (binomial[a - 1, b] + binomial[a - 1, b - 1]) % Mod;
      }
    }
    Int64[, ,] dp = new Int64[n * 2 + 1, cnt50 + 1, cnt100 + 1];
    dp[0, cnt50, cnt100] = 1;
    for (i = 0; ; ++i) {
      if (i == n * 2) {
        Console.WriteLine(-1);
        Console.WriteLine('0');
      } else if (i % 2 != 0 && dp[i, cnt50, cnt100] != 0) {
        Console.WriteLine(i);
        Console.WriteLine(dp[i, cnt50, cnt100]);
      }
      for (a = 0; a <= cnt50; ++a) {
        for (b = 0; b <= cnt100; ++b) {
          if (dp[i, a, b] != 0) {
            for (c = 0; c <= a; ++c) {
              for (d = 0; d <= b && c * 50 + d * 100 <= cap; ++d) {
                if (c + d != 0) {
                  Add(ref dp[i + 1, cnt50 - (a - c), cnt100 - (b - d)], dp[i, a, b] * binomial[a, c] % Mod * binomial[b, d] % Mod);
                }
              }
            }
          }
        }
      }
    }
  }

  // stuff cutline

  public static void Main() {
#if DEBUG
    Console.SetIn(new System.IO.StreamReader("..\\..\\in.txt"));
#endif
    var root = new Program();
    Console.Out.Flush();
  }

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

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

}


using System;

public sealed class Program {

  const Int64 Mod = 1000000007;

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

  public Program () {
    Int32[] token = ReadArray();
    Int32 n = token[0], cap = token[1], i, cnt50 = 0, cnt100 = 0, a, b, c, d;
    token = ReadArray();
    Array.Sort(token);
    if (cap < 50 || cap < token[n - 1] || n != 1 && cap < token[0] + token[1]) {
      Console.WriteLine(-1);
      Console.WriteLine('0');
      return;
    }
    foreach (Int32 body in token) {
      if (body == 50) {
        ++cnt50;
      } else {
        ++cnt100;
      }
    }
    Int64[,] binomial = new Int64[n + 1, n + 1];
    for (i = 0; i <= n; ++i) {
      binomial[i, 0] = binomial[i, i] = 1;
    }
    for (a = 2; a <= n; ++a) {
      for (b = 1; b < a; ++b) {
        binomial[a, b] = (binomial[a - 1, b] + binomial[a - 1, b - 1]) % Mod;
      }
    }
    Int64[, ,] dp = new Int64[2, cnt50 + 1, cnt100 + 1];
    dp[0, cnt50, cnt100] = 1;
    for (i = 0; ; ++i) {
      if (i % 2 != 0 && dp[i % 2, cnt50, cnt100] != 0) {
        Console.WriteLine(i);
        Console.WriteLine(dp[i % 2, cnt50, cnt100]);
        return;
      }
      for (a = 0; a <= cnt50; ++a) {
        for (b = 0; b <= cnt100; ++b) {
          if (dp[i % 2, a, b] != 0) {
            for (c = 0; c <= a; ++c) {
              for (d = 0; d <= b && c * 50 + d * 100 <= cap; ++d) {
                if (c + d != 0) {
                  Add(ref dp[1 - i % 2, cnt50 - (a - c), cnt100 - (b - d)], dp[i % 2, a, b] * binomial[a, c] % Mod * binomial[b, d] % Mod);
                }
              }
            }
          }
        }
      }
    }
  }

  // stuff cutline

  public static void Main() {
#if DEBUG
    Console.SetIn(new System.IO.StreamReader("..\\..\\in.txt"));
#endif
    var root = new Program();
    Console.Out.Flush();
  }

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

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

}


using System;

public sealed class Program {

  const Int64 Mod = 1000000007;

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

  public Program () {
    Int32 n = ReadInt(), cap = ReadInt(), i, cnt50 = 0, cnt100 = 0, a, b, c, d;
    for (i = 0; i < n; ++i) {
      if (ReadInt() == 50) {
        ++cnt50;
      } else {
        ++cnt100;
      }
    }
    Int64[,] binomial = new Int64[n + 1, n + 1];
    for (i = 0; i <= n; ++i) {
      binomial[i, 0] = binomial[i, i] = 1;
    }
    for (a = 2; a <= n; ++a) {
      for (b = 1; b < a; ++b) {
        binomial[a, b] = (binomial[a - 1, b] + binomial[a - 1, b - 1]) % Mod;
      }
    }
    Int64[, ,] dp = new Int64[n * 2 + 1, cnt50 + 1, cnt100 + 1];
    dp[0, cnt50, cnt100] = 1;
    for (i = 0; ; ++i) {
      if (i == n * 2) {
        Console.WriteLine(-1);
        Console.WriteLine('0');
      } else if (i % 2 != 0 && dp[i, cnt50, cnt100] != 0) {
        Console.WriteLine(i);
        Console.WriteLine(dp[i, cnt50, cnt100])
      }
      for (a = 0; a <= cnt50; ++a) {
        for (b = 0; b <= cnt100; ++b) {
          if (dp[i, a, b] != 0) {
            for (c = 0; c <= a; ++c) {
              for (d = 0; d <= b && c * 50 + d * 100 <= cap; ++d) {
                if (c + d != 0) {
                  Add(ref dp[i + 1, cnt50 - (a - c), cnt100 - (b - d)], dp[i, a, b] * binomial[a, c] % Mod * binomial[b, d] % Mod);
                }
              }
            }
          }
        }
      }
    }
  }

  // stuff cutline

  public static void Main() {
#if DEBUG
    Console.SetIn(new System.IO.StreamReader("..\\..\\in.txt"));
#endif
    var root = new Program();
    Console.Out.Flush();
  }

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

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

}


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

namespace CodeForces_Round_279
{
    class Program
    {
        static int nextint()
        {
            int a;
            a = int.Parse(Console.ReadLine());
            return a;
        }
        static string[] nextints()
        {
            string[] s = Console.ReadLine().Split();
            return s;
        }
        static bool[] left = new bool[1000010];
        static bool[] right = new bool[1000010];
        static bool checkever(long a, long b)
        {
            while (a % 3 == 0) a /= 3;
            while (a % 2 == 0) a /= 2;
            while (b % 3 == 0) b /= 3;
            while (b % 2 == 0) b /= 2;
            return a == b;
        }
        static void Main(string[] args)
        {
            int a, b, c, d;

            long first;
            long second;
            string[] arg = nextints();
            a = int.Parse(arg[0]);
            b = int.Parse(arg[1]);
            first = long.Parse(arg[0]) * long.Parse(arg[1]);
            arg=nextints();
            c = int.Parse(arg[0]);
            d = int.Parse(arg[1]);
            second = long.Parse(arg[0]) * long.Parse(arg[1]);
            if(!checkever(first,second))
            {
                Console.WriteLine(-1);
                return;
            }
            long ff=first;
            long ss=second;
            int num13 = 0;
            int num12 = 0;
            int num23 = 0;
            int num22 = 0;
            int div12 = 0;
            int div13 = 0;
            int div22 = 0;
            int div23 = 0;
            while (first % 3 == 0)
            {
                first /= 3;
                num13++;
            }
            first = ff;
            while (first % 2 == 0)
            { first /= 2; num12++; }
            while (second % 3 == 0)
            {
                second /= 3;
                num23++;
            }
            second = ss;
            int ans = 0;
            while (second % 2 == 0)
            {
                second /= 2;
                num22++;
            }
            //Console.WriteLine("Broj dvojki u prvom:" + num12);
            //Console.WriteLine("Broj trojki u prvom:" + num13);
            //Console.WriteLine("Broj dvojki u drugom:" + num22);
            //Console.WriteLine("Broj trojki u drugom:" + num23);
            if (num13 > num23)
            {
                div13 = num13 - num23;
                num12 += div13;
                if (num12 > num22)
                {
                    div12 = num12 - num22;
                }
                else
                {
                    div22 = num22 - num12;
                }
            }
            else
            {
                div23 = num23 - num13;
                num22 += div23;
                if (num12 > num22)
                {
                    div12 = num12 - num22;
                }
                else
                {
                    div22 = num22 - num12;
                }
            }
            for (int i = 0; i < div13; i++)
                if (a % 3 == 0) { a /= 3; a *= 2; }
                else { b /= 3; b *= 3; }
            for (int i = 0; i < div12; i++)
                if (a % 2 == 0) a /= 2;
                else b /= 2;
            for (int i = 0; i < div23; i++)
                if (c % 3 == 0) { c /= 3; c *= 2; }
                else { d /= 3; d *= 3; }
            for (int i = 0; i < div22; i++)
                if (c % 2 == 0) c /= 2;
                else d /= 2;
            Console.WriteLine(div12 + div13 + div22 + div23);
            Console.WriteLine(a+" "+b);
            Console.WriteLine(c + " " + d);
            //Console.ReadLine();
        }
    }
}


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

namespace CodeForces_Round_279
{
    class Program
    {
        static int nextint()
        {
            int a;
            a = int.Parse(Console.ReadLine());
            return a;
        }
        static string[] nextints()
        {
            string[] s = Console.ReadLine().Split();
            return s;
        }
        static bool[] left = new bool[1000010];
        static bool[] right = new bool[1000010];
        static bool checkever(long a, long b)
        {
            while (a % 3 == 0) a /= 3;
            while (a % 2 == 0) a /= 2;
            while (b % 3 == 0) b /= 3;
            while (b % 2 == 0) b /= 2;
            return a == b;
        }
        static void Main(string[] args)
        {
            int a, b, c, d;

            long first;
            long second;
            string[] arg = nextints();
            a = int.Parse(arg[0]);
            b = int.Parse(arg[1]);
            first = long.Parse(arg[0]) * long.Parse(arg[1]);
            arg=nextints();
            c = int.Parse(arg[0]);
            d = int.Parse(arg[1]);
            second = long.Parse(arg[0]) * long.Parse(arg[1]);
            /*if(!checkever(first,second))
            {
                Console.WriteLine(-1);
                return;
            }*/
            long ff=first;
            long ss=second;
            int num13 = 0;
            int num12 = 0;
            int num23 = 0;
            int num22 = 0;
            int div12 = 0;
            int div13 = 0;
            int div22 = 0;
            int div23 = 0;
            while (first % 3 == 0)
            {
                first /= 3;
                num13++;
            }
            first = ff;
            while (first % 2 == 0)
            { first /= 2; num12++; }
            while (second % 3 == 0)
            {
                second /= 3;
                num23++;
            }
            second = ss;
            int ans = 0;
            while (second % 2 == 0)
            {
                second /= 2;
                num22++;
            }
            //Console.WriteLine("Broj dvojki u prvom:" + num12);
            //Console.WriteLine("Broj trojki u prvom:" + num13);
            //Console.WriteLine("Broj dvojki u drugom:" + num22);
            //Console.WriteLine("Broj trojki u drugom:" + num23);
            if (num13 > num23)
            {
                div13 = num13 - num23;
                num12 += div13;
                if (num12 > num22)
                {
                    div12 = num12 - num22;
                }
                else
                {
                    div22 = num22 - num12;
                }
            }
            else
            {
                div23 = num23 - num13;
                num22 += div23;
                if (num12 > num22)
                {
                    div12 = num12 - num22;
                }
                else
                {
                    div22 = num22 - num12;
                }
            }
            for (int i = 0; i < div13; i++)
                if (a % 3 == 0) { a /= 3; a *= 2; }
                else { b /= 3; b *= 3; }
            for (int i = 0; i < div12; i++)
                if (a % 2 == 0) a /= 2;
                else b /= 2;
            for (int i = 0; i < div23; i++)
                if (c % 3 == 0) { c /= 3; c *= 2; }
                else { d /= 3; d *= 3; }
            for (int i = 0; i < div22; i++)
                if (c % 2 == 0) c /= 2;
                else d /= 2;
            long res1 = Convert.ToInt64(a) * Convert.ToInt64(b);
            long res2 = Convert.ToInt64(c) * Convert.ToInt64(d);
            if (res1 != res2) { Console.WriteLine(-1); return; }
            Console.WriteLine(div12 + div13 + div22 + div23);
            Console.WriteLine(a+" "+b);
            Console.WriteLine(c + " " + d);
            //Console.ReadLine();
        }
    }
}


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

namespace CodeForces_Round_279
{
    class Program
    {
        static int nextint()
        {
            int a;
            a = int.Parse(Console.ReadLine());
            return a;
        }
        static string[] nextints()
        {
            string[] s = Console.ReadLine().Split();
            return s;
        }
        static bool[] left = new bool[1000010];
        static bool[] right = new bool[1000010];
        static bool checkever(long a, long b)
        {
            while (a % 3 == 0) a /= 3;
            while (a % 2 == 0) a /= 2;
            while (b % 3 == 0) b /= 3;
            while (b % 2 == 0) b /= 2;
            return a == b;
        }
        static void Main(string[] args)
        {
            int a, b, c, d;

            long first;
            long second;
            string[] arg = nextints();
            a = int.Parse(arg[0]);
            b = int.Parse(arg[1]);
            first = long.Parse(arg[0]) * long.Parse(arg[1]);
            arg = nextints();
            c = int.Parse(arg[0]);
            d = int.Parse(arg[1]);
            second = long.Parse(arg[0]) * long.Parse(arg[1]);
            if (!checkever(first, second))
            {
                Console.WriteLine(-1);
                return;
            }
            long ff = first;
            long ss = second;
            int num13 = 0;
            int num12 = 0;
            int num23 = 0;
            int num22 = 0;
            int div12 = 0;
            int div13 = 0;
            int div22 = 0;
            int div23 = 0;
            while (first % 3 == 0)
            {
                first /= 3;
                num13++;
            }
            first = ff;
            while (first % 2 == 0)
            { first /= 2; num12++; }
            while (second % 3 == 0)
            {
                second /= 3;
                num23++;
            }
            second = ss;
            int ans = 0;
            while (second % 2 == 0)
            {
                second /= 2;
                num22++;
            }
            //Console.WriteLine("Broj dvojki u prvom:" + num12);
            //Console.WriteLine("Broj trojki u prvom:" + num13);
            //Console.WriteLine("Broj dvojki u drugom:" + num22);
            //Console.WriteLine("Broj trojki u drugom:" + num23);
            if (num13 > num23)
            {
                div13 = num13 - num23;
                num12 += div13;
                if (num12 > num22)
                {
                    div12 = num12 - num22;
                }
                else
                {
                    div22 = num22 - num12;
                }
            }
            else
            {
                div23 = num23 - num13;
                num22 += div23;
                if (num12 > num22)
                {
                    div12 = num12 - num22;
                }
                else
                {
                    div22 = num22 - num12;
                }
            }
            for (int i = 0; i < div13; i++)
                if (a % 3 == 0) { a /= 3; a *= 2; }
                else { b /= 3; b *= 3; }
            for (int i = 0; i < div12; i++)
                if (a % 2 == 0) a /= 2;
                else b /= 2;
            for (int i = 0; i < div23; i++)
                if (c % 3 == 0) { c /= 3; c *= 2; }
                else { d /= 3; d *= 2; }
            for (int i = 0; i < div22; i++)
                if (c % 2 == 0) c /= 2;
                else d /= 2;
            //Console.WriteLine(div12 + " " + div13 + " " + div22 + " " + div23);
            Console.WriteLine(div12 + div13 + div22 + div23);
            Console.WriteLine(a + " " + b);
            Console.WriteLine(c + " " + d);
            //Console.ReadLine();
        }
    }
}


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 a = sc.Long(4);
            var b = new long[4, 3];
            for (int i = 0; i < 4; i++)
            {
                var v = a[i];
                while (v % 2 == 0)
                {
                    b[i, 1]++;
                    v /= 2;
                }
                while (v % 3 == 0)
                {
                    b[i, 2]++;
                    v /= 3;
                }
                b[i, 0] = (int)v;
            }
            if (b[0, 0] * b[1, 0] != b[2, 0] * b[3, 0])
            {
                IO.Printer.Out.WriteLine(-1);
                return;
            }
            long ans=0;
            var three = Math.Min(b[0, 2] + b[1, 2], b[2, 2] + b[3, 2]);
            for (int i = 0; i < 4; i += 2)
            {
                var p = b[i, 2];
                var q = b[i + 1, 2];
                var diff = Math.Abs(p + q - three);
                if (p >= diff)
                {
                    b[i, 2] -= diff;
                    b[i, 1] += diff;
                }
                else
                {
                    b[i, 2] = 0;
                    b[i, 1] += p;
                    b[i + 1, 2] -= diff - p;
                    b[i + 1, 1] += diff - p;
                }
                ans+=diff;

            }
            var two = Math.Min(b[0, 1] + b[1, 1], b[2, 1] + b[3, 1]);
            for (int i = 0; i < 4; i += 2)
            {
                var p = b[i, 1];
                var q = b[i + 1, 1];
                var diff = Math.Abs(p + q - two);
                if (p >= diff)
                    b[i, 1] -= diff;
                else
                {
                    b[i, 1] = 0;
                    b[i + 1, 1] -= diff - p;
                }
                ans+=diff;

            }

            var c = new long[30];
            var d = new long[30];
            c[0] =d[0]= 1;
            for (int i = 1; i < 30; i++)
            {
                c[i] = c[i - 1] * 2;
                d[i] = d[i - 1] * 3;
            }

            var res = new long[4];
            for (int i = 0; i < 4; i++)
            {
                res[i] = b[i, 0] * c[b[i, 1]] * d[b[i, 2]];
            }
            IO.Printer.Out.WriteLine(ans);
            IO.Printer.Out.WriteLine("{0} {1}",res[0],res[1]);
            IO.Printer.Out.WriteLine("{0} {1}",res[2],res[3]);

        }
        struct State
        {
            public long[] a;
            public int t;
            public State(int q, params long[] ar)
                : this()
            {
                a = ar;
            }
        }
        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.OpenStandardOutput()) { AutoFlush = false };
#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) { Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(System.IO.Stream stream) { iStream = stream; }
        private readonly System.IO.Stream iStream;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private bool eof = false;
        public bool IsEndOfStream { get { return eof; } }
        const byte lb = 33, ub = 126, el = 10, cr = 13;
        public byte read()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b);            return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }
        public string Scan()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            var enc = System.Text.UTF8Encoding.Default;
            do
            {
                for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;
                if (ptr < len) break;
                ptr = 0;
                if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return ""; }
            } while (true);
            do
            {
                var f = ptr;
                for (; ptr < len; ptr++)
                    if (buf[ptr] < lb || ub < buf[ptr])
                    //if (buf[ptr] == cr || buf[ptr] == el)
                    {
                        string s;
                        if (sb == null) s = enc.GetString(buf, f, ptr - f);
                        else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }
                        ptr++; return s;
                    }
                if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));
                else sb.Append(enc.GetChars(buf, f, len - f));
                ptr = 0;

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


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public class Heap<T>
    {
        private readonly List<T> data;
        private readonly Comparison<T> compare;

        public Heap(Comparison<T> compare)
        {
            this.compare = compare;
            data = new List<T> { default(T) };
        }

        public int Count
        {
            get { return data.Count - 1; }
        }

        public T Peek()
        {
            return data[1];
        }

        public void Push(T item)
        {
            data.Add(item);
            var curPlace = Count;
            while (curPlace > 1 && compare(item, data[curPlace / 2]) < 0)
            {
                data[curPlace] = data[curPlace / 2];
                data[curPlace / 2] = item;
                curPlace /= 2;
            }
        }

        public T Pop()
        {
            var ret = data[1];
            data[1] = data[Count];
            data.RemoveAt(Count);
            var curPlace = 1;
            while (true)
            {
                var max = curPlace;
                if (Count >= curPlace * 2 && compare(data[max], data[2 * curPlace]) > 0)
                    max = 2 * curPlace;
                if (Count >= curPlace * 2 + 1 && compare(data[max], data[2 * curPlace + 1]) > 0)
                    max = 2 * curPlace + 1;
                if (max == curPlace)
                    break;
                var item = data[max];
                data[max] = data[curPlace];
                data[curPlace] = item;
                curPlace = max;
            }

            return ret;
        }
    }

    Dictionary<long, Tuple<int, int, int>> Dijkstra(int a, int b)
    {
        var dist = new Dictionary<Tuple<int, int>, int>();
        var q = new Heap<Tuple<int, int, int>>((t1, t2) => t1.Item1.CompareTo(t2.Item1));
        dist[Tuple.Create(a, b)] = 0;
        q.Push(Tuple.Create(0, a, b));
        while (q.Count > 0)
        {
            var t = q.Pop();
            if (dist[Tuple.Create(t.Item2, t.Item3)] < t.Item1)
                continue;
            if (t.Item2 % 3 == 0)
            {
                int nd = t.Item1 + 1;
                var key = Tuple.Create(t.Item2 / 3 * 2, t.Item3);
                if (!dist.ContainsKey(key) || dist[key] > nd)
                {
                    dist[key] = nd;
                    q.Push(Tuple.Create(nd, t.Item2 / 3 * 2, t.Item3));
                }
            }
            if (t.Item2 % 2 == 0)
            {
                int nd = t.Item1 + 1;
                var key = Tuple.Create(t.Item2 / 2, t.Item3);
                if (!dist.ContainsKey(key) || dist[key] > nd)
                {
                    dist[key] = nd;
                    q.Push(Tuple.Create(nd, t.Item2 / 2, t.Item3));
                }
            }
            if (t.Item3 % 3 == 0)
            {
                int nd = t.Item1 + 1;
                var key = Tuple.Create(t.Item2, t.Item3 / 3 * 2);
                if (!dist.ContainsKey(key) || dist[key] > nd)
                {
                    dist[key] = nd;
                    q.Push(Tuple.Create(nd, t.Item2, t.Item3 / 3 * 2));
                }
            }
            if (t.Item3 % 2 == 0)
            {
                int nd = t.Item1 + 1;
                var key = Tuple.Create(t.Item2, t.Item3 / 2);
                if (!dist.ContainsKey(key) || dist[key] > nd)
                {
                    dist[key] = nd;
                    q.Push(Tuple.Create(nd, t.Item2, t.Item3 / 2));
                }
            }
        }

        Dictionary<long, Tuple<int, int, int>> ret = new Dictionary<long, Tuple<int, int, int>>();
        foreach (var p in dist)
        {
            long key = 1L * p.Key.Item1 * p.Key.Item2;
            if (!ret.ContainsKey(key) || ret[key].Item1 > p.Value)
                ret[key] = Tuple.Create(p.Value, p.Key.Item1, p.Key.Item2);
        }
        return ret;
    }

    public object Solve()
    {
        int a1 = ReadInt();
        int b1 = ReadInt();
        int a2 = ReadInt();
        int b2 = ReadInt();

        var d1 = Dijkstra(a1, b1);
        var d2 = Dijkstra(a2, b2);

        var min = int.MaxValue;
        Tuple<int, int> ans1 = null;
        Tuple<int, int> ans2 = null;
        foreach (var p in d1)
        {
            if (d2.ContainsKey(p.Key) && p.Value.Item1 + d2[p.Key].Item1 < min)
            {
                min = p.Value.Item1 + d2[p.Key].Item1;
                ans1 = Tuple.Create(p.Value.Item2, p.Value.Item3);
                ans2 = Tuple.Create(d2[p.Key].Item2, d2[p.Key].Item3);
            }
        }

        if (min == int.MaxValue)
            return -1;

        Write(min);
        Write(ans1.Item1, ans1.Item2);
        Write(ans2.Item1, ans2.Item2);

        return null;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("instruction.in");
        //writer = new StreamWriter("instruction.out");
#endif
        try
        {
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            Console.WriteLine(ex);
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write

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

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

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

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

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

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

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

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

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

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

    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

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

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

    public static void Write<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }

    #endregion
}


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

namespace CodeForces_Round_279
{
    class Program
    {
        static int nextint()
        {
            int a;
            a = int.Parse(Console.ReadLine());
            return a;
        }
        static string[] nextints()
        {
            string[] s = Console.ReadLine().Split();
            return s;
        }
        static bool[] left = new bool[1000010];
        static bool[] right = new bool[1000010];
        static bool checkever(long a, long b)
        {
            while (a % 3 == 0) a /= 3;
            while (a % 2 == 0) a /= 2;
            while (b % 3 == 0) b /= 3;
            while (b % 2 == 0) b /= 2;
            return a == b;
        }
        static void Main(string[] args)
        {
            int a, b, c, d;

            long first;
            long second;
            string[] arg = nextints();
            a = int.Parse(arg[0]);
            b = int.Parse(arg[1]);
            first = long.Parse(arg[0]) * long.Parse(arg[1]);
            arg = nextints();
            c = int.Parse(arg[0]);
            d = int.Parse(arg[1]);
            second = long.Parse(arg[0]) * long.Parse(arg[1]);
            if (!checkever(first, second))
            {
                Console.WriteLine(-1);
                return;
            }
            long ff = first;
            long ss = second;
            int num13 = 0;
            int num12 = 0;
            int num23 = 0;
            int num22 = 0;
            int div12 = 0;
            int div13 = 0;
            int div22 = 0;
            int div23 = 0;
            while (first % 3 == 0)
            {
                first /= 3;
                num13++;
            }
            first = ff;
            while (first % 2 == 0)
            { first /= 2; num12++; }
            while (second % 3 == 0)
            {
                second /= 3;
                num23++;
            }
            second = ss;
            int ans = 0;
            while (second % 2 == 0)
            {
                second /= 2;
                num22++;
            }
            //Console.WriteLine("Broj dvojki u prvom:" + num12);
            //Console.WriteLine("Broj trojki u prvom:" + num13);
            //Console.WriteLine("Broj dvojki u drugom:" + num22);
            //Console.WriteLine("Broj trojki u drugom:" + num23);
            if (num13 > num23)
            {
                div13 = num13 - num23;
                num12 += div13;
                if (num12 > num22)
                {
                    div12 = num12 - num22;
                }
                else
                {
                    div22 = num22 - num12;
                }
            }
            else
            {
                div23 = num23 - num13;
                num22 += div23;
                if (num12 > num22)
                {
                    div12 = num12 - num22;
                }
                else
                {
                    div22 = num22 - num12;
                }
            }
            for (int i = 0; i < div13; i++)
                if (a % 3 == 0) { a /= 3; a *= 2; }
                else { b /= 3; b *= 2; }
            for (int i = 0; i < div12; i++)
                if (a % 2 == 0) a /= 2;
                else b /= 2;
            for (int i = 0; i < div23; i++)
                if (c % 3 == 0) { c /= 3; c *= 2; }
                else { d /= 3; d *= 2; }
            for (int i = 0; i < div22; i++)
                if (c % 2 == 0) c /= 2;
                else d /= 2;
            //Console.WriteLine(div12 + " " + div13 + " " + div22 + " " + div23);
            Console.WriteLine(div12 + div13 + div22 + div23);
            Console.WriteLine(a + " " + b);
            Console.WriteLine(c + " " + d);
            //Console.ReadLine();
        }
    }
}


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

namespace Chocolate
{
    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 a1 = Next();
            int b1 = Next();
            int a2 = Next();
            int b2 = Next();

            var m = new[]
                        {
                            new[] {GD(a1, 2), GD(b1, 2)},
                            new[] {GD(a1, 3), GD(b1, 3)},
                            new[] {GD(a2, 2), GD(b2, 2)},
                            new[] {GD(a2, 3), GD(b2, 3)},
                        };

            var l1 = new List<int>(GD(a1));
            l1.AddRange(GD(b1));
            l1.Sort();

            var l2 = new List<int>(GD(a2));
            l2.AddRange(GD(b2));
            l2.Sort();

            if (l1.Count != l2.Count)
            {
                writer.WriteLine("-1");
            }
            else
            {
                for (int i = 0; i < l1.Count; i++)
                {
                    if (l1[i] != l2[i])
                    {
                        writer.WriteLine("-1");
                        writer.Flush();
                        return;
                    }
                }

                int count = 0;
                while (m[1].Sum() != m[3].Sum())
                {
                    count++;
                    if (m[1].Sum() > m[3].Sum())
                    {
                        if (m[1][0] > 0)
                        {
                            m[0][0]++;
                            m[1][0]--;
                            a1 /= 3;
                            a1 *= 2;
                        }
                        else
                        {
                            m[0][1]++;
                            m[1][1]--;
                            b1 /= 3;
                            b1 *= 2;
                        }
                    }
                    else
                    {
                        if (m[3][0] > 0)
                        {
                            m[2][0]++;
                            m[3][0]--;
                            a2 /= 3;
                            a2 *= 2;
                        }
                        else
                        {
                            m[2][1]++;
                            m[3][1]--;
                            b2 /= 3;
                            b2 *= 2;
                        }
                    }
                }
                while (m[0].Sum() != m[2].Sum())
                {
                    count++;
                    if (m[0].Sum() > m[2].Sum())
                    {
                        if (m[0][0] > 0)
                        {
                            m[0][0]--;
                            a1 /= 2;
                        }
                        else
                        {
                            m[0][1]--;
                            b1 /= 2;
                        }
                    }
                    else
                    {
                        if (m[2][0] > 0)
                        {
                            m[2][0]--;
                            a2 /= 2;
                        }
                        else
                        {
                            m[2][1]--;
                            b2 /= 2;
                        }
                    }
                }

                writer.WriteLine(count);
                writer.Write(a1);
                writer.Write(' ');
                writer.WriteLine(b1);
                writer.Write(a2);
                writer.Write(' ');
                writer.WriteLine(b2);
            }

            writer.Flush();
        }

        private static IEnumerable<int> GD(int n)
        {
            while (n%2 == 0)
            {
                n /= 2;
            }
            while (n%3 == 0)
            {
                n /= 3;
            }
            for (int i = 5; i*i <= n; i += 2)
            {
                while (n%i == 0)
                {
                    yield return i;
                    n /= i;
                }
            }
            if (n != 1)
                yield return n;
        }

        private static int GD(int n, int d)
        {
            for (int i = 0;; i++)
            {
                if (n%d == 0)
                    n /= d;
                else
                {
                    return i;
                }
            }
        }

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = data[0];
            var k = data[1];
            var line = Console.ReadLine();
            var strings = new HashSet<string>();

            var sb = new StringBuilder();
            var q = new Queue<string>();
            q.Enqueue(line);
            while (strings.Count < k && q.Count > 0)
            {
                var current = q.Dequeue();
                strings.Add(current);
                for (int i = 0; i < current.Length; i++)
                {
                    sb.Clear();
                    for (int j = 0; j < current.Length; j++)
                    {
                        if(j == i)
                            continue;
                        sb.Append(current[j]);
                    }

                    var otherString = sb.ToString();
                    if (strings.Add(otherString))
                        q.Enqueue(otherString);
                    if(strings.Count == k)
                        break;
                }
            }

            if (strings.Count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            var res = k*n - strings.Sum(x => x.Length);
            Console.WriteLine(res);
        }
    }
}


using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    int N;
    long K;
    string S;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextLong();
        S = sc.Next();

        // iまで見た、スキップj個 最後文字
        var dp = new long[N + 1, N + 1, 27];
        dp[0, 0, 26] = 1;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j <= i; j++)
            {

                for (int c = 0; c <= 26; c++)
                {
                    // s_iを使う
                    dp[i + 1, j, S[i] - 'a'] += dp[i, j, c];

                    // 使わない
                    if (S[i] - 'a' != c) dp[i + 1, j + 1, c] += dp[i, j, c];
                }
            }
        }

        long[] cnt = new long[N + 1];
        for (int i = 0; i <= N; i++)
        {
            for (int c = 0; c <= 26; c++)
            {
                cnt[i] += dp[N, i, c];
            }
        }

        long ans = 0;
        for (int i = 0; i <= N && K > 0; i++)
        {
            // Console.WriteLine($"{i} {cnt[i]} {K}");
            if (cnt[i] < K)
            {
                ans += cnt[i] * i;
                K -= cnt[i];
            }
            else
            {
                ans += i * K;
                K = 0;
            }
        }

        if (K > 0)
        {
            Console.WriteLine("-1");
            return;
        }

        Console.WriteLine(ans);
    }

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

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

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

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

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

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

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

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


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

namespace Trenya260619
{
    class Input
    {
        private static IEnumerator<string> _getinput()
        {
            while (true)
                foreach (string s in Console.ReadLine().Split().Where(x => x.Length > 0))
                    yield return s;
        }

        private IEnumerator<string> input = _getinput();

        public string GetString()
        {
            input.MoveNext();
            return input.Current;
        }

        public int GetInt() { return int.Parse(GetString()); }
        public long GetLong() { return long.Parse(GetString()); }
        public double GetDouble() { return double.Parse(GetString()); }
    }

    class Program
    {
        static Input csin = new Input();

        static void Main(string[] args)
        {
            int n = csin.GetInt();
            long k = csin.GetLong();
            List<int> s = csin.GetString().Select(x => (int)(x - 'a')).ToList();
            s.Add(26);

            long[,] d = new long[n + 1, n + 1]; // i - length, j - first index

            d[0, n] = 1;

            bool[] ex = new bool[27];

            for (int len = 1; len <= n; len++)
                for (int start = 0; start < n; start++)
                {
                    for (int i = 0; i < 27; i++) ex[i] = false;

                    for (int j = start + 1; j <= n; j++)
                    {
                        if (ex[s[j]]) continue;
                        ex[s[j]] = true;
                        d[len, start] += d[len - 1, j];
                    }
                }

            long[] lenans = new long[n + 1];
            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j < 27; j++) ex[j] = false;

                for (int j = 0; j <= n; j++)
                {
                    if (ex[s[j]]) continue;

                    lenans[i] += d[i, j];
                    ex[s[j]] = true;
                }
            }

            long ans = 0;

            for (int i = n; i >= 0 && k > 0; i--)
            {
                long curr = Math.Min(k, lenans[i]);
                k -= curr;
                ans += curr * (n - i);
            }

            if (k > 0) ans = -1;

            Console.WriteLine(ans);
            //Console.ReadKey();
        }

    }
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		HashSet<String> h = new HashSet<String>();
		h.Add("");
		for(int i=0;i<N;i++){
			var t = S[i].ToString();
			var nh = new HashSet<String>();
			foreach(var s in h){
				nh.Add(s);
				nh.Add(s + t);
			}
			var l = nh.ToList();
			l.Sort((a, b) => -1 * (a.Length.CompareTo(b.Length)));
			h = new HashSet<String>();
			for(int j=0;j<Math.Min(K,l.Count);j++) h.Add(l[j]);
		}

		int cost = 0;
		if(h.Count < K){
			Console.WriteLine(-1);
			return;
		}

		foreach(var s in h) cost += N - s.Length;
		Console.WriteLine(cost);

	}
	int N,K;
	String S;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = data[0];
            var k = data[1];
            var line = Console.ReadLine();
            var strings = new HashSet<string>();

            var sb = new StringBuilder();
            var q = new Queue<string>();
            q.Enqueue(line);
            while (strings.Count < k && q.Count > 0)
            {
                var current = q.Dequeue();
                strings.Add(current);
                if (strings.Count == k)
                    break;
                for (int i = 0; i < current.Length; i++)
                {
                    sb.Clear();
                    for (int j = 0; j < current.Length; j++)
                    {
                        if(j == i)
                            continue;
                        sb.Append(current[j]);
                    }

                    var otherString = sb.ToString();
                    if (strings.Add(otherString))
                        q.Enqueue(otherString);
                    if(strings.Count == k)
                        break;
                }
            }

            if (strings.Count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            var res = k*n - strings.Sum(x => x.Length);
            Console.WriteLine(res);
        }
    }
}


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

public class Program
{
    int N, K;
    string S;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        S = sc.Next();

        /*
         * Sの部分列tを取る集合に加える
         * コスト n-|t|
         * 重複不可
         *
         * サイズkの集合つくる最小コスト
         */

        /*
         * t = s 1個
         *
         * |t| = |s|-1 N個
         */

        var hs = new HashSet<string>(StringComparer.Ordinal);
        hs.Add(S);
        var q = new Queue<string>();
        q.Enqueue(S);

        long ans = 0;
        for (int i = 0; i < K; i++)
        {
            if (q.Count <= 0)
            {
                Console.WriteLine("-1");
                return;
            }

            var d = q.Dequeue();
            ans += N - d.Length;
            if (d.Length <= 0) continue;
            char[] tmp = new char[d.Length - 1];
            for (int j = 0; j < d.Length - 1; j++)
            {
                tmp[j] = d[j + 1];
            }

            for (int j = 0; j < d.Length; j++)
            {
                var str = new string(tmp);
                if (hs.Add(str))
                {
                    q.Enqueue(str);
                }
                if (j < d.Length - 1) tmp[j] = d[j];
            }

        }

        Console.WriteLine(ans);
    }

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

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

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

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

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

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

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

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


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

namespace Trenya260619
{
    class Input
    {
        private static IEnumerator<string> _getinput()
        {
            while (true)
                foreach (string s in Console.ReadLine().Split().Where(x => x.Length > 0))
                    yield return s;
        }

        private IEnumerator<string> input = _getinput();

        public string GetString()
        {
            input.MoveNext();
            return input.Current;
        }

        public int GetInt() { return int.Parse(GetString()); }
        public long GetLong() { return long.Parse(GetString()); }
        public double GetDouble() { return double.Parse(GetString()); }
    }

    class Program
    {
        static Input csin = new Input();

        static void Main(string[] args)
        {
            int n = csin.GetInt();
            long k = csin.GetLong();
            int[] s = csin.GetString().Select(x => (int)(x - 'a')).Append(26).ToArray();

            long[,] d = new long[n + 1, n + 1]; // i - length, j - first index

            d[0, n] = 1;

            bool[] ex = new bool[27];

            for (int len = 1; len <= n; len++)
                for (int start = 0; start < n; start++)
                {
                    for (int i = 0; i < 27; i++) ex[i] = false;

                    for (int j = start + 1; j <= n; j++)
                    {
                        if (ex[s[j]]) continue;
                        ex[s[j]] = true;
                        d[len, start] += d[len - 1, j];
                    }
                }

            long[] lenans = new long[n + 1];
            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j < 27; j++) ex[j] = false;

                for (int j = 0; j <= n; j++)
                {
                    if (ex[s[j]]) continue;

                    lenans[i] += d[i, j];
                    ex[s[j]] = true;
                }
            }

            long ans = 0;

            for (int i = n; i >= 0 && k > 0; i--)
            {
                long curr = Math.Min(k, lenans[i]);
                k -= curr;
                ans += curr * (n - i);
            }

            if (k > 0) ans = -1;

            Console.WriteLine(ans);
            //Console.ReadKey();
        }

    }
}


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

namespace Graph
{
    class Program
    {
        static void Main(string[] args)
        {
            string num = Console.ReadLine();
            string str = Console.ReadLine();

            int res = 0;
            bool done = false;
            int n = str.Length;
            for (int i = 0; i < n; i++)
            {
                //res = i;
                //Console.WriteLine(i + " " + str + " " + done + " " + n);
                if(str.Length == 0 ){
                    Console.WriteLine(res);
                    return;
                }

                if (!done)
                {

                    for (int j = 0; j < num.Length; j++)
                    {
                        if (num[j] == '9' || num[j] == '6')
                        {
                            if (str.IndexOf('9') != -1)
                            {
                                str = str.Remove(str.IndexOf('9'), 1);
                            }
                            else
                            {
                                if (str.IndexOf('6') != -1)
                                {
                                    str = str.Remove(str.IndexOf('6'), 1);
                                }
                                else
                                {
                                    //Console.WriteLine("Нет девятки и шестерки");
                                    done = true;
                                    Console.WriteLine(res);
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (num[j] == '5' || num[j] == '2')
                            {
                                if (str.IndexOf('5') != -1)
                                {
                                    str = str.Remove(str.IndexOf('5'), 1);
                                }
                                else
                                {
                                    if (str.IndexOf('2') != -1)
                                    {
                                        str = str.Remove(str.IndexOf('2'), 1);
                                    }
                                    else
                                    {
                                        //Console.WriteLine("Нет двойки и пятерки");
                                        done = true;
                                        Console.WriteLine(res);
                                        return;
                                    }
                                }
                            }
                            else {
                                if (str.IndexOf(num[j]) != -1)
                                {
                                    str = str.Remove(str.IndexOf(num[j]), 1);
                                }
                                else {
                                    //Console.WriteLine("Нет " + num[j]);
                                    done = true;
                                    Console.WriteLine(res);
                                    return;
                                    //break;
                                }

                            }
                        }
                    }

                    res++;
                }
            }

            Console.WriteLine(res);
        }
    }
}