Problem: Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days.

Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity.

Input

The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).

Output

If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k.

Examples

Input

3 2 2


Output

1 1 2 
1 2 1 


Input

3 2 1


Output

-1

Note

Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day.

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;

public class GenericProblem
{
	/*
	 * This FastReader code is taken from GeeksForGeeks.com
	 * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
	 * 
	 * The article was written by Rishabh Mahrsee
	 */
	public static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }

	
	public static void main(String[] args)
	{
		FastReader file = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = file.nextInt(), k = file.nextInt(), d = file.nextInt();
		k = Math.min(n, k); // Remove unnecessary buses
		
		// PSUEDOCODE
		
		/*
		 * create an 2d array in which the numbers 1, 2, 3, ..., n are evenly distributed
		 * between the k buses
		 * 
		 * Do a Level-order-Traversal like algorithm like so for every bus and level in the queue:
		 * The queue will start out with the entire bus
		 * 
		 * Attempt to divide up the bus as much as possible for the next day creating k distinct
		 * sub-friend groups that are only friends with each other
		 * 
		 * Add these divisions that were made to the queue
		 * 
		 * repeat until all of the groups are of size 1 or less
		 * 
		 * print the result after each level of the traversal
		 * 
		 * Notes: the number of steps this will take is logk( ceil(n / k) ) or
		 * Math.log(Math.ceil(n / (double)k)) / Math.log(k);
		 * 
		 * So that means that the number of steps must be <= d - 1, otherwise print -1
		 */
		
		int stepCount = 0;
		StringBuilder result = new StringBuilder();
		
		int[][] busArrangement = new int[k][(int)Math.ceil(n / (double) k)];
		int[] len = new int[k];
		
		reset(busArrangement, n, k, len);
		result.append(format(busArrangement) + "\n");
		
		stepCount++;
		
		// Level order traversal
		Queue<Integer> startQ = new LinkedList<>();
		Queue<Integer> endQ = new LinkedList<>();
		
		startQ.add(0);
		endQ.add(busArrangement[0].length - 1);
		
		while (!finished(startQ, endQ) && stepCount <= d + 1) // Prevents TLE
		{
			int size = startQ.size();
			for (int i = 0; i < size; i++)
			{
				int start = startQ.poll();
				int end = endQ.poll();
				
				if (start == end)
					continue;
				
				int elemsLeft = end - start + 1;
				int groupsLeft = k;
				
				int rot = 0;
				for (int student = start; student <= end && student < busArrangement[0].length; student++)
				{
					int oldStart = student;
					for (int j = 0; j < elemsLeft / groupsLeft && student <= end && student < busArrangement[0].length; j++)
					{
						for (int bus = 0; bus < k; bus++)
						{
							if (busArrangement[bus][student] != -1)
								busArrangement[bus][student] = (busArrangement[bus][student] + rot) % k;
						}
						student++;
					}
					student--;
					
					if (elemsLeft / groupsLeft > 0) // We don't want to visit it again if it had 0 elements
					{
						startQ.add(oldStart);
						endQ.add(student);
					}
					
					
					rot++;
					elemsLeft -= elemsLeft / groupsLeft;
					groupsLeft--;
					
					
				}
			}
			result.append(format(busArrangement) + "\n");
			reset(busArrangement, n, k, len);
			stepCount++;
		}
		
		int timesLeft = d - stepCount;
		
		if (timesLeft < 0)
		{
			out.println(-1);
			out.close();
			return;
		}
		
		for (int i = 0; i < timesLeft; i++)
		{
			result.append(format(busArrangement) + "\n");
		}
		
		out.println(result);
		
		out.close();
	}
	
	private static boolean finished(Queue<Integer> startQ, Queue<Integer> endQ)
	{
		Iterator<Integer> it1 = startQ.iterator();
		Iterator<Integer> it2 = endQ.iterator();
		
		while (it1.hasNext())
		{
			if (it1.next() < it2.next())
			{
				return false;
			}
		}
		return true;
	}

	private static void reset(int[][] busArrangement, int n, int k, int[] len)
	{
		for (int i = 0; i < busArrangement.length; i++)
		{
			Arrays.fill(busArrangement[i], -1);
		}
		int i = 0;
		// Make sure to print the extra buses first
		for (; i < n % k; i++)
		{
			len[i] = busArrangement[0].length;
			for (int j = 0; j < busArrangement[0].length; j++)
			{
				busArrangement[i][j] = i;
			}
		}
		
		for (; i < k; i++)
		{
			len[i] = n / k;
			for (int j = 0; j < n / k; j++)
			{
				busArrangement[i][j] = i;
			}
		}
	}

	public static String format(int[][] arr)
	{
		StringBuilder res = new StringBuilder();

		for (int[] a : arr)
		{
			for (int i : a)
			{
				if (i != -1)
					res.append((i + 1) + " ");
			}
		}
		
		return res.substring(0, res.length() - 1);
	}
}