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.keySet().stream()
.collect(Collectors.groupingBy(map::get)).entrySet().stream()
.filter(e -> e.getValue().size() > 1)
.flatMap(e -> e.getValue().stream())
.forEach(map::remove);
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwuc3RyZWFtLkNvbGxlY3RvcnM7CgpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIE1hcDxTdHJpbmcsIFN0cmluZz4gbWFwID0gbmV3IEhhc2hNYXA8PigpOwogICAgICAgIG1hcC5wdXQoItCf0YPQv9C60LjQvSIsICLQktCw0YHQuNC70LjQuSIpOwogICAgICAgIG1hcC5wdXQoItCY0LLQsNC90L7QsiIsICLQktCw0YHQuNC70LjQuSIpOwogICAgICAgIG1hcC5wdXQoItCf0YPRiNC60LjQvSIsICLQkNC70LXQutGB0LDQvdC00YAiKTsKCiAgICAgICAgbWFwLmtleVNldCgpLnN0cmVhbSgpCiAgICAgICAgCS5jb2xsZWN0KENvbGxlY3RvcnMuZ3JvdXBpbmdCeShtYXA6OmdldCkpLmVudHJ5U2V0KCkuc3RyZWFtKCkKICAgICAgICAJCS5maWx0ZXIoZSAtPiBlLmdldFZhbHVlKCkuc2l6ZSgpID4gMSkKICAgICAgICAJCS5mbGF0TWFwKGUgLT4gZS5nZXRWYWx1ZSgpLnN0cmVhbSgpKQogICAgICAgIAkJLmZvckVhY2gobWFwOjpyZW1vdmUpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihtYXApOwogICAgfQp9