## COCI '07 Contest 3 #3 Tajna

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 32M

Problem type

Every evening, little Ivica sends secret messages to little Marica through e-mail. Knowing Ivica's e-letter travels unguarded through the network on its way to Marica's e-mailbox, they have decided to encrypt every message using the following algorithm:

• Suppose Ivica's message consists of characters.
• Ivica must first find a matrix consisting of rows and columns such that and . If there is more than one such matrix, Ivica chooses the one with the most rows.
• Ivica writes his message into the matrix in row-major order. In other words, he writes the first segment of the message into the first row, the second segment into the second row and so on.
• The message he sends to Marica is the matrix read in column-major order.

Marica has grown tired of spending her precious time deciphering Ivica's messages, so you must write a program to do it for her.

#### Input Specification

The input contains the received message, a string of lowercase letters of the English alphabet (with no spaces).

The number of letters will be between and .

#### Output Specification

Output the original (decrypted) message.

#### Sample Input 1

bok

#### Sample Output 1

bok

#### Sample Input 2

koaski

#### Sample Output 2

kakosi

#### Sample Input 3

boudonuimilcbsai

#### Sample Output 3

bombonisuuladici

Ivica wants to send the message bombonisuuladici containing letters. He can use a , or matrix. Of these, the has the most rows. When the message is written into it, the matrix looks like this:

 b o m b o n i s u u l a d i c i