Problem list
Log in
#coci00051 · COCI 2007/2008 Contest 3

Tajna

Bronze I 1.0 s 32 MB

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 $N$ characters.
  • Ivica must first find a matrix consisting of $R$ rows and $C$ columns such that $R \le C$ and $R \cdot C = N$. 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.

For example, to decrypt boudonuimilcbsai ($16$ letters), the matrix is $4 \times 4$ (the most rows with $R \le C$ and $R \cdot C = 16$). Filling it from the received message in column-major order and reading it back row-major gives the original bombonisuuladici:

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

Input

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 $1$ and $100$.

Output

Output the original (decrypted) message.

Example 1

Input
bok
Output
bok

Example 2

Input
koaski
Output
kakosi

Example 3

Input
boudonuimilcbsai
Output
bombonisuuladici
Source
COCI 2007/2008 Contest 3
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 1 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code