Counting the number of ordered triples How would I count the the number of ordered triples of different numbers $(X_1, X_2, X_3)$, where $X_i$ could be any positive integer from $1$ to $N_i$, inclusive $(i = 1, 2, 3)$. 
If the input was $(3,3,3)$ the ordered triples formed from that would be 
$(1, 2, 3)$
$(1, 3, 2)$
$(2, 1, 3)$
$(2, 3, 1)$
$(3, 1, 2)$
$(3, 2, 1)$ 
and the answer would be $6$.
So, if someone could tell me how you would create those ordered triples out of the initial $(3,3,3)$ that would be great
I think one of the problems here for me is that I dont really understand what makes a number and ordered triple. 
 A: Wlog. $N_1\le N_2\le N_3$.
The triples $(a,b,c)$ can be categorized as follows:


*

*$b,c\le N_1$. There are $N_1(N_1-1)(N_1-2)$ possibilities

*$b>N_1$, $c\le N_1$. There are $N_1(N_1-1)\cdot (N_2-N_1)$ possibilities

*$b\le N_1$, $c>N_1$. There are $N_1(N_1-1)\cdot (N_3-N_1)$ possibilities

*$b>N_1$, $N_1<c\le N_2$. There are $(N_2-N_1)(N_2-N_1-1)\cdot N_1$ possibilities

*$b>N_1$, $c>N_2$. There are $N_1(N_2-N_1)(N_3-N_2)$ possibilities.


If you sum these up, you obtain
$$ N_1^3-(N_2+1)N_1^2+(N_3-1)N_2N_1-(N_3-2)N_1,$$
I think.
A: The following argument counts the number of ordered triples but also gives you an algorithm to generate the triples:
Let us assume $N_1\leq N_2 \leq N_3$. For the first element of the triple you can choose any number out of the $N_1$. 
The second element, you are not allowed to choose the one that is already taken by the first, so these are $N_2 -1$ elements.
For the third element it goes equivalently: you can choose any but the one taken for the first or second element so $N_3-2$ elements.
In total you thus have $N_1(N_2 -1) (N_3-2)$ possibilities...
A: Say the input has three numbers p, q, r. Sort the numbers in non-decreasing order and then you will have the number of such ordered triples as p*(q-1)*(r-2)
This problem is from a running contest at Codechef, but I am posting the answer as it will still require some effort to get the solution accepted there. ALthough the idea is correct, and hint is enough.
