/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		for (int i = 0; i < 100000; i++) {

            Set<Object> set = new LinkedHashSet<>();

            long items = Math.round(Math.random() * 10);

            for (int j = 0; j < items; j++) {
                set.add(Double.toHexString(Math.random() * 1232330));
            }

            byte[] source = toBytes(set);
            Object obj = toObject(source);
            byte[] result = toBytes(obj);

            for (int j = 0; j < source.length; j++) {
                if (source[j] != result[j]) {
                    throw new Exception("CHO ZA HOOINYA?");
                }
            }
        }
        System.out.println("OK!");
	}
	
	static byte[] toBytes(Object obj) throws Exception {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            ObjectOutput out = new ObjectOutputStream(bos);
            out.writeObject(obj);
            out.flush();
            return bos.toByteArray();
        } finally {
            try {
                bos.close();
            } catch (IOException ex) {
                // ignore close exception
            }
        }
    }

    static Object toObject(byte[] bytes) throws Exception {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInput in = null;
        try {
            in = new ObjectInputStream(bis);
            return in.readObject();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                // ignore close exception
            }
        }
    }
}