public class Solution { public static void main(String[] args) throws Exception { ArrayList<Integer> listA = new ArrayList<Integer>(); ArrayList<Integer> listEven = new ArrayList<Integer>(); ArrayList<Integer> listOdd = new ArrayList<Integer>(); ArrayList<Integer> listThird = new ArrayList<Integer>(); int z; BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); for (int i = 0; i < 20; i++) { z = Integer.parseInt(bf.readLine()); listA.add(z); if (z % 3 == 0) { listThird.add(z); } if (z % 2 == 0) { listEven.add(z); } if ((z % 3) != 0 && (z % 2) != 0) { listOdd.add(z); } } //printList(listA); printList(listThird); printList(listEven); printList(listOdd); //напишите тут ваш код } public static void printList(ArrayList<Integer> list) { for (int i = 0; i < list.size(); i++) System.out.println(list.get(i)); //напишите тут ваш код } }