🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"easy","problem_code":"ZEROONE","problem_name":"01 Subsequence","problemComponents":{"constraints":"- $ 1 \\leq T \\leq 1000 $\n- $ 1 \\leq N \\leq 100 $\n- $ 1 \\leq  C_i \\leq 1000 $\n","constraintsState":true,"subtasks":"- 30 points : $1 \\leq R \\leq 10000$\n- 70 points : $1 \\leq R \\leq 10^9$\n","subtasksState":false,"inputFormat":"- The first line contains $T$ - the number of test cases. Then the test cases follow.\n- The first line of each test case contains a single integer $N$ - the size of the array $C$.\n- The second line of each test case contains $N$ integers $C_1, C_2, \\dots, C_N$ - the $\\texttt{01}$-compression representation of $S$.","inputFormatState":true,"outputFormat":"For each test case, output two lines: the first line contains $N$ integers representing the optimal array $C$, and the second line contains the maximum number of $\\texttt{01}$ subsequences.","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"1\n4\n2 3 4 3","output":"4 3 2 3\n30","explanation":"- **Test case $1$:** $C = [2, 3, 4, 3]$, which means $S$ corresponds to $\\texttt{001110000111}$. The optimal list of operations is to only swap $C_1$ and $C_3$, resulting in $C = [4, 3, 2, 3]$ and $S = $ $\\texttt{000011100111}$, which has $30$ subsequences of $\\texttt{01}$.","isDeleted":false}}},"video_editorial_url":"","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"prasant21","problem_tester":"","date_added":"21-10-2021","tags":{"0":"cook134","1":"prasant21","2":"simple","3":"sorting"},"problem_difficulty_level":"Unavailable","best_tag":"","editorial_url":"https://discuss.codechef.com/problems/ZEROONE","time":{"view_start_date":1635100202,"submit_start_date":1635100202,"visible_start_date":1635100202,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=ZEROONE","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
### Read problem statements in [Mandarin](https://www.codechef.com/download/translated/COOK134/mandarin/ZEROONE.pdf), [Bengali](https://www.codechef.com/download/translated/COOK134/bengali/ZEROONE.pdf), and [Russian](https://www.codechef.com/download/translated/COOK134/russian/ZEROONE.pdf) as well.

You are handed a binary string $S$, but not in any ordinary form. Instead of being directly given the value of $S$, you are given an array $C$ of size $N$ representing the *01-compression representation* of $S$. This means $S$ first contains $C_1$ $\texttt{0}$ characters, then $C_2$ $\texttt{1}$ characters, then $C_3$ $\texttt{0}$ characters, and so on. For example, the array $C = [2, 3, 4, 3]$ corresponds with the binary string $\texttt{001110000111}$.

You are allowed to modify $S$ by swapping elements of $C$. More specifically, you are allowed to swap $C_i$ and $C_j$ *as long as* $C_i$ and $C_j$ both encodes blocks of the same character. For example, from $C = [2, 3, 4, 3]$, you can swap $C_1$ and $C_3$ because both of them encode blocks of $\texttt{0}$'s, turning $C$ to $[4, 3, 2, 3]$ and $S$ to $\texttt{000011100111}$. However, you cannot swap $C_1$ and $C_2$ because $C_1$ encodes a block of $\texttt{0}$'s, while $C_2$ encodes a block of $\texttt{1}$s.

Perform the swapping operation in any way as many times as you want (including zero times) so that the final string $S$ has as many $\texttt{01}$ subsequences as possible. As a reminder, a subsequence of a string is a sequence that can be derived by deleting zero or more characters without changing the order of the remaining characters.

You need to find any optimal final array $C$, for which the number of $\texttt{01}$ subsequence will be the largest possible.
<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>