Under construction

Still being built. Things may change

Image Shrinking

Interview

Time limit2sMemory limit1024 MB

Summary
Given an enlarged image formed by scaling each axis by an integer factor, recover an original image of smallest area.
Level

Medium5 of 10

Topics
Implementation, Brute force, Number theory, Math
Solved
No attempts yet

Problem

There is a rectangular image with nn pixels of height and mm pixels of width. Jeonghwi chose suitable positive integers ii and jj, scaled the image's height by a factor of ii and its width by a factor of jj, and produced an image with nini pixels of height and mjmj pixels of width. For some reason the original image was deleted, so Jeonghwi asks you to reconstruct it.

Given the enlarged image, find and output the smallest possible original image. For convenience, each pixel is represented by a lowercase letter (a, b, ... , z, ASCII codes 97-122).

Input

The first line gives the dimensions of the enlarged image as integers nini and mjmj, separated by a space.

From the second line, nini lines follow, each containing mjmj letters that represent the pixel values of the image.

Output

Output the possible original image with the smallest area.

The first line contains the height and width of the original image as integers nn and mm, separated by a space.

From the second line, nn lines follow, each containing mm letters that represent the original image.

If multiple answers are possible, output any one of them.

Constraints

  • 1≤ni,mj≤1 0001 \leq ni, mj \leq 1\,000
  • Each pixel of the image is represented by a lowercase letter (a, b, ... , z, ASCII codes 97-122).

Examples1

  1. Example 1

    Input
    3 6
    aabbaa
    bbaabb
    aabbaa
    
    Expected output
    3 3
    aba
    bab
    aba