Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/Codeforces/Codeforces Round 1059/B. Beautiful String
PrevNext
CodeforcesCodeforces
Pupil
Codeforces Round 1059

B. Beautiful String

ArrayStringGreedy
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

You are given a binary

βˆ—

 string π‘ 

 of length π‘›

.

Your task is to find any subsequence

†

 π‘

 of π‘ 

 such that:

  • The subsequence π‘
  •  is non-decreasing. That is, each character in π‘
  •  is not greater than the next one.
  • Let π‘₯
  •  denote the string obtained by removing all characters of π‘
  •  from π‘ 
  • , while preserving the order of the remaining characters. Then π‘₯
  •  must be a palindrome
  • ‑
  • .

You only need to output any valid subsequence π‘

 that satisfies both conditions. If no such subsequence exists, output βˆ’1

.

Note that an empty string is both non-decreasing and a palindrome.


βˆ—

A binary string is a string consisting of characters '0' and '1'.



†

A subsequence of a string π‘ =𝑠

1

𝑠

2

…𝑠

𝑛

 is a sequence π‘=𝑠

𝑖

1

𝑠

𝑖

2

…𝑠

𝑖

π‘˜

 such that 1≀𝑖

1

<𝑖

2

<…<𝑖

π‘˜

≀𝑛

. The characters are selected in order, but not necessarily contiguously. Note that an empty string is a subsequence of any string.


‑

A string π‘‘=𝑑

1

𝑑

2

…𝑑

π‘š

 is a palindrome if π‘‘

𝑖

=𝑑

π‘šβˆ’π‘–+1

 for all 1β‰€π‘–β‰€π‘š

. In other words, the string reads the same forward and backward.

Input


The first line contains a single integer π‘‘

 (1≀𝑑≀3000

) β€” the number of test cases.

The first line of each test case contains a single integer π‘›

 (1≀𝑛≀10

) β€” the length of the string.

The second line contains a binary string π‘ 

 of length π‘›

.

Output


If a solution exists:

  • On the first line, print a single integer π‘˜
  •  (0β‰€π‘˜β‰€π‘›
  • ) β€” the length of the subsequence π‘
  • .
  • On the second line, print π‘˜
  •  distinct integers π‘–
  • 1
  • ,𝑖
  • 2
  • ,…,𝑖
  • π‘˜
  •  (1≀𝑖
  • 1
  • <𝑖
  • 2
  • <β‹―<𝑖
  • π‘˜
  • ≀𝑛
  • ) β€” the indices of the characters in π‘ 
  •  that form π‘
  •  (in order as they appear in π‘ 
  • ).

Otherwise, print a single line containing βˆ’1

.

Example

Input

Copy

5
3
010
3
001
5
00111
8
11010011
6
100101

Output

Copy

0

2
2 3
5
1 2 3 4 5
2
3 4
2
5 6

Note


In the first test case, we remove an empty string, resulting in π‘₯=𝟢𝟷𝟢

, which is a palindrome.

In the second test case, we remove π‘=𝟢𝟷

 (indices 2

, 3

), resulting in π‘₯=𝟢

, which is a palindrome.

In the third test case, we remove π‘=𝟢𝟢𝟷𝟷𝟷

 (indices 1

 to 5

), resulting in an empty string, which is trivially a palindrome.

In the fourth test case, we remove π‘=𝟢𝟷

 (indices 3

, 4

), resulting in π‘₯=𝟷𝟷𝟢𝟢𝟷𝟷

, which is a palindrome.

In the fifth test case, we remove π‘=𝟢𝟷

 (indices 5

, 6

), resulting in π‘₯=𝟷𝟢𝟢𝟷

, which is a palindrome.

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Codeforces Round 1059
Previous ProblemNext Problem