This page is still under construction.

Parts of this page are still being built. What you see may change.

Next partition into terms

Time limit2sMemory limit1024 MB

Summary
Given a partition of n written in nondecreasing order, print the next partition in lexicographic order, or No solution if none exists.
Level

Medium6 of 10

Topics
Greedy, Math, Combinatorics, Implementation
Solved
No attempts yet

Problem

A partition of a number nn into terms is a multiset of positive integers whose sum is nn. Partitions that differ only in the order of their terms are considered the same, so we may assume the terms of a partition are sorted in nondecreasing order.

For example, there are 7 partitions of 5 into terms:

\begin{align*} 5&=1+1+1+1+1\\ 5&=1+1+1+2\\ 5&=1+1+3\\ 5&=1+2+2\\ 5&=1+4\\ 5&=2+3\\ 5&=5 \end{align*}

In the example above the partitions are ordered lexicographically: first by the first term of the partition, then by the second term, and so on. In this problem you are given a partition into terms and must find the next partition in lexicographic order.

Input

The input file contains one line, a partition of the number nn into terms (1≤n≤100 0001 \le n \le 100\,000). The terms of the partition are given in nondecreasing order.

Output

Print to the output file one line, the partition of nn into terms that comes next in lexicographic order after the one in the input file. If the input file contains the last partition of nn into terms, print <<No solution>>.

Examples2

  1. Example 1

    Input
    5=1+1+3
    
    Expected output
    5=1+2+2
    
  2. Example 2

    Input
    5=5
    
    Expected output
    No solution