description: Introduces pairs, which allow you to store two objects (possibly of different types) as a single unit, as well as tuples, which are a generalization of pairs.
Storing multiple elements as a signle unit allows you to change the order of the elements (e.g. sorting) without mixing one component with another. For example, if you had some points on a plane with given coordinates `x[i]` and `y[i]` for i'th point, and the task is sorting these points with the increasing order of `x` coordinate and increasing order of `y` coordinate in case it is a tie. Now, if you sort one of `x[i]` and `y[i]` without considering the other, the points will be mixed incorrectly. However, sorting the points with considering `x[i]` and `y[i]` as a signle unit, we will have the expected result.
While sorting an array of pairs without any comparator, the priority is given to the first element of pairs, then the second element of them in case it is tie. So, to solve the problem mentioned early, it would be correct to create an array of pairs with elements `{x[i], y[i]}` and [sort](https://usaco-guide.netlify.app/bronze/intro-sorting) them.
Of course, we can hold more than two values with something like `pair<int,pair<int,int>>`, but it gets messy when you need a lot of elements. In this case, using tuples or [custom classes/structs](https://usaco-guide.netlify.app/silver/sorting-custom) might be more convenient.
- `tuple<type1, type2, ..., typeN> t`: Creates a tuple with `N` elements, i'th one being of `typei`.
- `make_tuple(a, b, c, ..., d)`: Returns a tuple with values written in the brackets.
- `get<i>(t)`: Returns the i'th element of the tuple `t`. Only works for constant i (must be some number, not variable). Apperantly, can be used to change the element of a tuple.
- `tie(a, b, c, ..., d) = t`: Equals `a, b, c, ..., d` to the elements of the tuple t accordingly.
This is not frequently used by competitive programmers, but it is good to know and can help you to simplify things sometimes. Also, it is possible to sort an array of tuples. Without using any comparator, sorting tuples will first sort by the first element, then the second, and so on.
If you have an array ```pair[]arr=new pair[100]```, make sure each element of this array is not null. You can call ```Arrays.sort(arr);``` on this array and it will sort it by all the ```first``` of the array and if there is a tie in ```first``` it will sort by ```second```.
You can also use an `int[]` as a pair, or if you're using a pair of two different types, you can use `Object[]`.
If you want to sort by 3 or more elements, it's a simple change. Just add a new variable in ```pair``` and make sure the comparable compares in the right order you want.