To celebrate the victory of the war, Pisces has decided to build a splendid palace. The craftsmen has brought back \(n\) kinds of cube materials from the dwarf kingdom. The length, width, and height of each material are \(a\), \(b\) and \(c\) respectively. To make the palace magnificent, the craftsmen have to stack these materials together. Material \(i\) can be stacked on material \(j\) if and only if \(a_i < a_j \bigcap b_i < b_j\), or \(a_i < b_j \bigcap b_i < a_j\). Pisces wants to know how high these materials can stack at most.