QOJ.ac

QOJ

Points totaux : 100 Indisponible

#11678. Boxes

Statistiques

There are $n$ boxes arranged in a row. Among them, two adjacent boxes are empty. The remaining boxes contain $n/2 - 1$ red balls and $n/2 - 1$ green balls. Each box contains at most one ball.

Bajtazar has invented a very interesting game, which consists of moving balls between boxes so that, in the end, all red balls are located before all green balls. In each single move, you are allowed to move two adjacent balls into the empty boxes, provided that their relative order is not changed during this operation. Bajtazar has come to you for help in writing a program to play this game.

The first line of the result file should contain the number of moves $m$ required to perform the sorting. Each of the following $m$ lines should contain a single number $p_k$ ($0 \le p_k \le n - 2$), describing the $k$-th move. The move described by the number $p_k$ consists of moving the ball from box $p_k$ to the left empty box, and the ball from box $p_k + 1$ to the right empty box.

Input

The first line contains a single even integer $n$ ($8 \le n \le 200\,000$), representing the number of boxes on the table. The boxes are numbered from 0, starting from the left. The next line contains an $n$-character string consisting of the digits 0, 1, and 2. The consecutive digits in the string correspond to consecutive boxes 0, 1, 2, .... The digit 0 means there is a red ball in the box, 1 means there is a green ball in the box, and 2 represents an empty box.

Examples

Input 1

10
0110220101

Output 1

5
1
3
5
8
2

ou importez des fichiers un par un

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.