🧞

Hmm...

Something unexpected happened with this submission. Let's see if Genie can help.

Day 3 : The Spices Box

hardBacktracking with pruning
Imagine you are a merchant having nn spice boxes. The weight ithi^{th} spice box is wiw_i. You can sell only spice sets having total weight 250g. So you need to make 3 groups of spice boxes such that each group has total weight 250g and no spice box is left ungrouped.
You need to determine whether it's possible or not. If possible you need to output the groups.

Input Format:

The first line of input contains nn the number of spice boxes. The second line contains nn integers w1w_{1} w2w_{2} w3w_{3} .... wnw_{n}, denoting the weights of the spice boxes.

Output Format:

You need to output "YES" or "NO" (without quotes and capitalized) denoting whether it's possible or not to make such groups.
If Yes then you need to output the groups in three lines, each line should contain the weights of the spice box present in the group.

Constraints:

(1n101 \le n \le 10).
(1wi2501 \le w_{i} \le 250)

Examples:

Example 1:

Input:

10
150 20 20 10 80 130 110 90 100 40

Output:

YES
150 20 80 
20 10 130 90 
110 100 40

Code

Loading Editor...