Image Shrinking
InterviewTime limit2sMemory limit1024 MB
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 pixels of height and pixels of width. Jeonghwi chose suitable positive integers and , scaled the image's height by a factor of and its width by a factor of , and produced an image with pixels of height and 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 and , separated by a space.
From the second line, lines follow, each containing 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 and , separated by a space.
From the second line, lines follow, each containing letters that represent the original image.
If multiple answers are possible, output any one of them.
Constraints
- Each pixel of the image is represented by a lowercase letter (
a,b, ... ,z, ASCII codes 97-122).