public class Solution { public static void printList(ArrayList<Integer> list) { for (int x: list) { System.out.println(x); } } public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); ArrayList<Integer> mainLisst = new ArrayList<Integer>(); for (int i = 0; i < 20; i++) { mainLisst.add(Integer.parseInt(reader.readLine())); } ArrayList<Integer> splitedOfTwo = new ArrayList<>(); ArrayList<Integer> splitedOfThree = new ArrayList<>(); ArrayList<Integer> other = new ArrayList<>(); for(int x :mainLisst){ if(x%2==0) { splitedOfTwo.add(x); } else if (x % 2== 0 && x% 3==0){ splitedOfTwo.add(x); splitedOfThree.add(x); } else if (x%3==0){ splitedOfThree.add(x); } else { other.add(x); } } printList(splitedOfTwo); printList(splitedOfThree); printList(other); } }