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

#PS0000123. Các vị trí chia có điểm lớn nhất (All Divisions With the Highest Score of a Binary Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Các vị trí chia có điểm lớn nhất (All Divisions With the Highest Score of a Binary Array)

All Divisions With the Highest Score of a Binary Array

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given a binary array a0,…,an−1a_0,\ldots,a_{n-1}, choose a division index ii between 0 and nn, inclusive. The left part contains the first ii entries and the right part contains the last n−in-i entries. Either part may be empty at an endpoint. The score counts zeros on the left and ones on the right. Find every division index attaining the maximum score.

Input

The first line contains nn. The second line contains nn integers a0,…,an−1a_0,\ldots,a_{n-1}.

Output

Print one line containing all maximizing division indices separated by spaces. Each index must appear once; any order is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1001\le n\le100; ai∈{0,1}a_i\in\{0,1\} for 0≤i<n0\le i<n.
  • Subtask 2 (30 points): 1≤n≤1051\le n\le10^5; ai∈{0,1}a_i\in\{0,1\} for 0≤i<n0\le i<n; a0≤a1≤⋯≤an−1a_0\le a_1\le\cdots\le a_{n-1}.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; ai∈{0,1}a_i\in\{0,1\} for 0≤i<n0\le i<n.

Example 1

Input

4
0 0 1 0

Output

2 4

Explanation

Scores at indices 0 through 4 are 1,2,3,2,3. The maximum 3 occurs at 2 and 4; 4 2 is also accepted.

Example 2

Input

3
0 0 0

Output

3

Explanation

Scores are 0,1,2,3. Only index 3 maximizes the score.

Example 3

Input

2
1 1

Output

0

Explanation

Scores are 2,1,0; only 0 is optimal.