public static int median(InputStream in) {
		ByteArrayOutputStream bos= new ByteArrayOutputStream();
		byte[]buffer=new byte[1024];
		int len=0;
		try {
			while ((len=in.read(buffer))>-1) bos.write(buffer,0,len);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		InputStream in1=new ByteArrayInputStream(bos.toByteArray());
		InputStream in2=new ByteArrayInputStream(bos.toByteArray());
		Scanner sc=new Scanner(in1);
		int total=0,c=0,mu=0;
		TreeMap<Integer, Integer> map=new TreeMap<>();
		while (sc.hasNext()) {
			++total;
			int key=sc.nextInt()>>16;
			Integer v=map.get(key);
			if (v==null) map.put(key, 1);
			else map.put(key, v+1);
		} 
		for (Map.Entry<Integer,Integer>e:map.entrySet())
			if ((c+e.getValue())>total/2) {mu=e.getKey();break;} 
			else c+=e.getValue();
		map.clear();
		sc=new Scanner(new BufferedInputStream(in2));
		List<Integer> list=new ArrayList<>();
		while (sc.hasNext()) {
			int key=sc.nextInt();
			if ((key>>16)==mu) list.add(key);
		}
		Collections.sort(list);
		return list.get(total/2-c);
	}