import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.*;
import java.util.stream.Collectors;
class Ideone
{
public static void main
(String[] args
) { Map
<String, String
> map
= new HashMap
<>(); map.put("Пупкин", "Василий");
map.put("Иванов", "Василий");
map.put("Пушкин", "Александр");
Map
<String, String
> result
= new HashMap
<>();
map.entrySet()
.stream()
.
collect(Collectors.
groupingBy(Map.Entry::getValue
)) .entrySet()
.stream()
.filter(entry -> entry.getValue().size() == 1)
.forEach(listEntry -> result.put(listEntry.getKey(), listEntry.getValue().get(0).getKey()));
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwuc3RyZWFtLkNvbGxlY3RvcnM7CgpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIE1hcDxTdHJpbmcsIFN0cmluZz4gbWFwID0gbmV3IEhhc2hNYXA8PigpOwogICAgICAgIG1hcC5wdXQoItCf0YPQv9C60LjQvSIsICLQktCw0YHQuNC70LjQuSIpOwogICAgICAgIG1hcC5wdXQoItCY0LLQsNC90L7QsiIsICLQktCw0YHQuNC70LjQuSIpOwogICAgICAgIG1hcC5wdXQoItCf0YPRiNC60LjQvSIsICLQkNC70LXQutGB0LDQvdC00YAiKTsKCiAgICAgICAgTWFwPFN0cmluZywgU3RyaW5nPiByZXN1bHQgPSBuZXcgSGFzaE1hcDw+KCk7CgogICAgICAgIG1hcC5lbnRyeVNldCgpCiAgICAgICAgICAgICAgICAuc3RyZWFtKCkKICAgICAgICAgICAgICAgIC5jb2xsZWN0KENvbGxlY3RvcnMuZ3JvdXBpbmdCeShNYXAuRW50cnk6OmdldFZhbHVlKSkKICAgICAgICAgICAgICAgIC5lbnRyeVNldCgpCiAgICAgICAgICAgICAgICAuc3RyZWFtKCkKICAgICAgICAgICAgICAgIC5maWx0ZXIoZW50cnkgLT4gZW50cnkuZ2V0VmFsdWUoKS5zaXplKCkgPT0gMSkKICAgICAgICAgICAgICAgIC5mb3JFYWNoKGxpc3RFbnRyeSAtPiByZXN1bHQucHV0KGxpc3RFbnRyeS5nZXRLZXkoKSwgbGlzdEVudHJ5LmdldFZhbHVlKCkuZ2V0KDApLmdldEtleSgpKSk7CgogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihyZXN1bHQpOwogICAgfQp9