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

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

/* 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
	{
		Map<String,Integer> map = new HashMap<String,Integer>();
		map.put("eggs",1500); 
        map.put("echo",150); 
        map.put("foo",320); 
        map.put("smt",50);
		
		
	List<Map.Entry<String,Integer>> sortedList = new ArrayList<Map.Entry<String,Integer>>(
		map
		    .entrySet() 
            .stream() 
            .sorted((o1, o2) -> (o2.getValue()).compareTo( o1.getValue()))
            .collect(Collectors.toList())
    );
	List<String> word_used = new ArrayList<String>(
		sortedList
		    .stream()
            .map(Map.Entry<String,Integer>::getKey)
            .collect(Collectors.toList())
    );
	List<Integer> ints_used = new ArrayList<Integer>(
		sortedList
		    .stream()
            .map(Map.Entry<String,Integer>::getValue)
            .collect(Collectors.toList())
    );
    
    for (String s : word_used) {
    	System.out.println(s);
    }
    for (Integer i : ints_used) {
    	System.out.println(i);
    }
	}
}