My Number
Time limit1sMemory limit256 MB
Build an array B of at most 12 integers, then write an expression over B with +, -, *, and brackets for each target A_i.
- Level
Medium7 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Taaaamara is a big fan of the Serbian quiz Slagalica. Her favorite game in the quiz is My Number. In this game you get a set of integers and one target number . You can use each element of at most once and some mathematical operations to build a valid expression equal to . For example, if and , one valid expression is .
Today, Taaaamara is playing a modification of this game:
- She has an array with integers, all of them target numbers.
- She needs to find an array with elements (elements of do not have to be different). All elements of must be integers in the range .
- She wants to build one valid expression for each target number using only elements from . If some element appears times in , each expression can use that element at most times.
- She can use the binary operators
+(addition),-(subtraction), and*(multiplication). Division is not allowed. She can also use brackets. - The length of array is not fixed, but it must not be bigger than ().
Can you help her?
Input
The first line contains an integer (). The second line contains integers, the array ().
Output
In the first line, print the integer , the length of array . In the second line, print the integers of . Each of the next lines contains one valid expression, where the -th line has a value equal to . Expressions must follow these rules:
- Each expression has at most 1000 characters.
- Addition uses
+(ASCII 43). - Subtraction uses
-(ASCII 45). - Multiplication uses
*(ASCII 42). - Brackets use
((ASCII 40) and)(ASCII 41). +and-cannot be used as unary operators. For example,-5 + 3and5 - -3are not valid.- Besides these characters, you can only use numbers from and spaces (ASCII 32).
Special formatting of the output is not needed.