PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000211. Sắp xếp bằng đảo dãy con (Reverse Sort)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sắp xếp bằng đảo dãy con (Reverse Sort)

Reverse Sort

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Ashish has a binary string ss of length nn and wants to sort it in non-decreasing order, with all 0 digits before all 1 digits.

In one operation, select a subsequence of positions, not necessarily consecutive, 1≤i1<i2<⋯<iq≤n1\le i_1<i_2<\cdots<i_q\le n. Before the operation, the digits at those positions must form a non-increasing sequence:

si1≥si2≥⋯≥siq.s_{i_1}\ge s_{i_2}\ge\cdots\ge s_{i_q}.

Reverse the selected digits and write them back into the same positions; all unselected positions remain unchanged. For example, selected digits 1100 become 0011 after reversal.

Find the minimum number of operations needed to sort the string, and output operations achieving it. If the input is already sorted, no operation is needed.

Input

  • The first line contains an integer nn, the string length.
  • The second line contains a binary string ss of exactly nn characters.

Output

  • The first line contains the integer mm, the minimum number of operations needed.
  • Print exactly mm further lines. Each line contains an integer qq followed by exactly qq strictly increasing indices i1,i2,…,iqi_1,i_2,\ldots,i_q numbered from 11. At the moment of that operation, selected digits must be non-increasing.

If m=0m=0, print only 0. Any shortest valid sequence of operations is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; s∈{0,1}ns\in\{0,1\}^n; operation indices are integers from 11 through nn.
  • Subtask 2 (30 points): 1≤n≤2001\le n\le200; s∈{0,1}ns\in\{0,1\}^n; operation indices are integers from 11 through nn.
  • Subtask 3 (50 points): 1≤n≤10001\le n\le1000; s∈{0,1}ns\in\{0,1\}^n; operation indices are integers from 11 through nn.

Examples

Input

5
10100

Output

1
4 1 3 4 5

Explanation

The input 10100 contains three zeros and two ones, so the sorted target is 00011. The original differs from the target, hence zero operations cannot suffice. Choose indices 1, 3, 4, 5; their current digits are 1100, which are non-increasing. Reversing them yields 0011, changing the entire string into 00011. Thus the minimum is one operation, and 4 1 3 4 5 is a valid operation line.