class Pair{ int first; int second; Pair(int first,int second){ this.first=first; this.second=second; } public boolean equals(Object o) { if (o instanceof Pair) { Pair p = (Pair)o; return p.first == first && p.second == second; } return false; } public int hashCode() { return new Integer(first).hashCode() * 31 + new Integer(second).hashCode(); } }