package com.codegym.task.task07.task0713;

import java.io.BufferedReader;z
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/*
Playing Javarella

*/

public class Solution {
    public static void main(String[] args) throws Exception {
        //write your code here
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Integer> mainList  = new ArrayList<Integer>();
        ArrayList<Integer> num3List  = new ArrayList<Integer>();
        ArrayList<Integer> num2List = new ArrayList<Integer>();
        ArrayList<Integer>otherList  = new ArrayList<Integer>();

      // while(true){                                             //please note that it is the same syntax from the previous lecture.
      //  String s = reader.readLine();
        //    if (s.isEmpty()) break;
        //   mainList.add(Integer.parseInt(s));
     //  }

        for (int i =0; i<20; i++)
        {
            String s = reader.readLine();
            mainList.add(Integer.parseInt(s));
        }

        for (int x=0; x<mainList.size(); x++){

            if (mainList.get(x) % 3 == 0)

                num3List.add(mainList.get(x));

            if (mainList.get(x) % 2 == 0)

                num2List.add(mainList.get(x));

            if ((mainList.get(x) % 3 != 0 && mainList.get(x) % 2 != 0))
                 otherList.add(mainList.get(x));
        }

          printList(num3List);
          printList(num2List);
          printList(otherList);


    }

    public static void printList(List<Integer> list) {
        //write your code here
        for (Integer x : list)
        System.out.println(x);
    }
}