binar
Let's take a sequence of N binary digits B=(b1, b2, ..., bN). We build matrix M as follows:
- the first line of matrix M is sequence B;
- every line of matrix M (except the first line) is obtained from the previous line via a circular permutation to the left.
b1 b2 ... bN-1 bN
b2 b3 ... bN b1
...
bN-1 bN ... bN-3 bN-2
bN b1 ... bN-2 bN-1
Then, the lines of
matrix M are sorted in lexicographical
order (obviously, 0<1).
Task
Write a program that reads the last column of matrix M
(after the lexicographical sorting) which determines the first line of matrix
M (also after lexicographical
sorting).
Input Data
Input file binar.in contains
on line one a positive integer N,
which represents the length of binary sequence B.
The second line of the input file contains N
binary digits, separated by spaces, representing the last column of matrix M.
Output Data
Output file binar.out will contain a single line with the N binary digits representing the first line of matrix M. The N binary digits will not be separated using spaces.
Constraints
0 < N <= 1000
Examples
binar.in | binar.out | binar.in | binar.out |
5 1 0 0 1 0 |
00011 | 8 1 1 0 1 1 0 1 0 |
00111011 |
Marinel Serban
"Gr. C. Moisil" Iaşi IT High School
marinel_serban@yahoo.com