publicclassMain{ publicstaticvoidmain(String[] args){ Scanner in = new Scanner(System.in); Map<Integer, Integer> hash = new TreeMap<>(); int n = in.nextInt(); for (int i = 0; i < n; i++) { int x = in.nextInt(); int y = in.nextInt(); if (hash.containsKey(x)) { hash.put(x, hash.get(x) + y); } else { hash.put(x, y); } } for (Map.Entry<Integer, Integer> entry : hash.entrySet()) { System.out.println(entry.getKey() + " " + entry.getValue()); } } }