cswork / OAOpen practice workspace

ReevoOA #2

Balanced Numbers (Permutation-of-[1..k] Subarrays)

Estimated MediumJudge-ready

Topics (AI-labelled)In-place ArraysPrefix & Ranges

You are given a permutation p in which each integer 1..n appears exactly once. For each length k=1..n, if some contiguous subarray has an element set exactly equal to {1,2,…,k}, the k-th character of the answer string is 1; otherwise it is 0.

The catalog's original examples and outputs are kept; this site explicitly defines the permutation domain as 1..n and adds n≤2000 to match the O(n²) algorithm and the I/O. The claim "any single element is balanced" in the original example explanation is imprecise: by the set definition, only the value 1 is balanced for length 1, but a permutation always contains 1, so the existence output is still 1.

Input

The first line is n, and the second line is a permutation p of 1..n. Bounds on this site: 1≤n≤2000.

Output

Output a 0/1 string of length n; the k-th character from the left corresponds to length k.

Example 1

Input:

4
4 1 3 2

Output:

1011

Example 2

Input:

3
2 3 1

Output:

101

Example 3

Input:

2
2 1

Output:

11

Editorial

Loading solution…