!
package com.javarush.task.task07.task0713;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Играем в Jолушку
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < 20; i++) list.add(Integer.parseInt(reader.readLine()));
ArrayList<Integer> listA = new ArrayList<Integer>();
ArrayList<Integer> listB = new ArrayList<Integer>();
ArrayList<Integer> listC = new ArrayList<Integer>();
for (int i = 0; i < list.size(); i++){
Integer x = list.get(i);
if (x % 3 == 0)
listA.add(x);
else if (x % 2 == 0)
listB.add(x);
else if (x % 2 == 0 && x % 3 == 0) {
listA.add(x);
listB.add(x);}
else if (x % 2 != 0 || x % 3 != 0)
listC.add(x);
}
printList(listA);
printList(listB);
printList(listC);
}
public static void printList(ArrayList<Integer> list) {
for(Integer i : list) {
System.out.println(i);
}
}
}