Generating patterns
시간 제한1.5초메모리 제한2048 MB
8비트 기본 패턴 B와 XOR 이동을 적용할 순서를 정해, 영에서 시작해 주어진 N비트 문자열을 최소 횟수로 만들고 그 B와 최소 횟수를 출력한다.
문제
Sandy is developing a new computer as part of the ambitious System for Binary Compression (SBC) project. This project is part of a major technological challenge known as the Interface for Compact Pattern Coding (ICPC), whose goal is to achieve maximum efficiency in writing large volumes of data.
The SBC proposal is bold: choose a base pattern , consisting of bits , and from it generate any other pattern by applying only simple, fast operations.
Sandy wants to write a sequence of bits to memory, with , denoted by . Initially, memory contains only zeros. She may then repeat the following operation any number of times:
- Choose an integer between and , the position at which will be applied;
- For each position of that overlaps the sequence, that is, for every from to such that , replace with , where denotes the XOR (exclusive OR) operation.
The following example illustrates two applications of the procedure: applying pattern to content , the final result is obtained.

Since the data we want to write to memory is usually not random, Sandy believes that, with a good choice of base pattern , it will be possible to produce the desired content with few operations.
To test this hypothesis, she needs your help: given the content that must be written to memory, determine the base pattern that minimizes the number of operations needed to generate as described, and also the number of operations required.
It can be proven that it is always possible to write any content using this procedure. However, for the SBC project to be successful and earn the ICPC seal of excellence, your solution needs to be fast and efficient!
입력
The first line contains an integer (), the length of .
The second line contains a sequence of bits, representing , the content that must be written to memory.
출력
Your program should print a single line containing the -bit sequence , representing the base pattern that minimizes the number of operations, and an integer , representing the minimum number of operations.
If there is more than one pattern that minimizes the number of operations, print the one with the smallest integer value when interpreted in base , where is the most significant bit and is the least significant bit.