import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.Scanner; public class Main2 { static int n, m; static ArrayList a, b; public static void main(String[] args) { try (Scanner scan = new Scanner(System.in)) { n = Integer.parseInt(scan.next()); a = new ArrayList<>(); for(int i=0; i(); for(int i=0; i > checkList = new LinkedList<>(); LinkedList< ArrayList > nextCheckList = new LinkedList<>(); checkList.add(a); for(int i=0; i nowList = checkList.poll(); boolean flag = false; for(Integer v : nowList) { if(b.get(i) < v) { flag = true; break; } } if(flag) continue; nodeList.clear(); solve(0, b.get(i), new ArrayList(), nowList); for(int k=0; k pList = nodeList.get(k).list; ArrayList tmpList = (ArrayList)nowList.clone(); for(int j=0; j >)nextCheckList.clone(); nextCheckList.clear(); } System.out.println(-1); } } static ArrayList nodeList = new ArrayList<>(); static void solve(int i, int box, ArrayList list, ArrayList a) { ArrayList tmpList = (ArrayList)list.clone(); if(i == a.size()) { Node node = new Node(box, (ArrayList)list.clone()); for(Node now : nodeList) { if(node.equals(now)) { return; } } nodeList.add(node); return; } solve(i+1, box, tmpList, a); if((box - a.get(i)) >= 0) { tmpList.add(a.get(i)); solve(i+1, box-a.get(i), tmpList, a); } } static class Node implements Comparable { int rem; ArrayList list; Node(int rem, ArrayList list) { this.rem = rem; this.list = list; } @Override public int compareTo(Node o) { if(rem == o.rem) { if(list.size() == o.list.size()) { for(int i=0; i