CF BUDDY
← Problems·

1743D · Problem with Random Tests

1700 · brute force, dp, greedy

Problem: You are given a string ss consisting of nn characters. Each character of ss is either 0 or 1.

A substring of ss is a contiguous subsequence of its characters.

You have to choose two substrings of ss (possibly intersecting, possibly the same, possibly non-intersecting — just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:

  • let s1s_1 be the first substring, s2s_2 be the second chosen substring, and f(si)f(s_i) be the integer such that sis_i is its binary representation (for example, if sis_i is 11010, f(si)=26f(s_i) = 26);
  • the value is the bitwise OR of f(s1)f(s_1) and f(s2)f(s_2).

Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.

Input Format: The first line contains one integer nn — the number of characters in ss.

The second line contains ss itself, consisting of exactly nn characters 0 and/or 1.

All non-example tests in this problem are generated randomly: every character of ss is chosen independently of other characters; for each character, the probability of it being 1 is exactly 12\frac{1}{2}.

This problem has exactly 4040 tests. Tests from 11 to 33 are the examples; tests from 44 to 4040 are generated randomly. In tests from 44 to 1010, n=5n = 5; in tests from 1111 to 2020, n=1000n = 1000; in tests from 2121 to 4040, n=106n = 10^6.

Hacks are forbidden in this problem.

Output Format: Print the maximum possible value you can get in binary representation without leading zeroes.

Note: In the first example, you can choose the substrings 11010 and 101. f(s1)=26f(s_1) = 26, f(s2)=5f(s_2) = 5, their bitwise OR is 3131, and the binary representation of 3131 is 11111.

In the second example, you can choose the substrings 1110010 and 11100.

Sample Cases

Case 1

Input

5
11010

Output

11111

Case 2

Input

7
1110010

Output

1111110

Case 3

Input

4
0000

Output

0

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback